2014-10-28 3 views
0

두 클래스가 있습니다 직원부서입니다.최대 절전 모드를 사용하여 열 업데이트

public class Employee { 
    int empId; 
    String empName; 
    Boolean isEmpAvailable; 
    String empAddress; 
    Department department; 

} 


public class Department { 
    int deptId; 
    String deptName; 
    } 

나는 Department.hbm.xml 및 Employee.hbm.xml

내가 부서 테이블에 deptid에 테이블 직원 내놓고에서 열 isEmpAvailable를 업데이트하려면 두 클래스에 대한 최대 절전 모드 파일 파일을 만들었습니다. 내가 열이 업데이 트를하지 않는 코드를 실행하면

여기에 내가 온라인 문서

 public void updateEmployee(Employee emp, Department deptid){ 
      String query= " update Employee set isEmpAvailable=? where deptid=? 
      Object[] values= {"true","133"}; 
      getHibernateTemplate.update(query,values); 
     } 

에서 읽은 후에 명확하지 않다 업데이트 쿼리와 문제에 직면하고있다. 엔티티가 인식되지 않음 : 업데이트 직원 세트 isEmpAvailable =? 어디 deptid =?

getHibernateTemplate() 메소드가 정수로 반환되는 온라인 문서를 읽었습니다. 여기서는 returntype없이 dao.updateEmployee를 호출하여 데이터베이스 지시문을 업데이트하려고합니다. 나는 그것을 할 수 없다. 당신은 또한 saveOrUpdate() 기능을 사용할 수 원하는 경우

String hqlUpdate = 
    "update Employee e " + 
    "set e.isEmpAvailable = :isEmpAvailable " + 
    "where e.deptid = :deptid"; 
int updatedEntities = session.createQuery(hqlUpdate) 
    .setBoolean("isEmpAvailable", isEmpAvailable) 
    .setInt("deptid", deptid) 
    .executeUpdate(); 

OR 

String jpqlUpdate = 
    "update Employee e " + 
    "set e.isEmpAvailable = :isEmpAvailable " + 
    "where e.deptid = :deptid"; 
int updatedEntities = entityManager.createQuery(jpqlUpdate) 
    .setBoolean("isEmpAvailable", isEmpAvailable) 
    .setInt("deptid", deptid) 
    .executeUpdate(); 

OR 

String hqlVersionedUpdate = 
    "update versioned Employee e " + 
    "set e.isEmpAvailable = :isEmpAvailable " + 
    "where e.deptid = :deptid"; 
int updatedEntities = s.createQuery(hqlUpdate) 
    .setBoolean("isEmpAvailable", isEmpAvailable) 
    .setInt("deptid", deptid) 
    .executeUpdate(); 
+0

두 클래스에 @Entity 주석을 추가하십시오. –

+0

질문에 대한 스택 트레이스를 추가하십시오. 또한 hibernate.cfg.xml 파일을 보여줍니다. – Chaitanya

+0

이것은 최대 절전 모드에서의 업데이트를 이해하는 데 도움이 될 수 있습니다. http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch11.html – Atiq

답변

2

업데이트를 제안하십시오. this link에는 예제 및 일부 문서가 있습니다.

0

: 나에게 최대 절전 모드에서이 방법을 수행

관련 문제