简体   繁体   中英

Hibernate4 update not working - LocalSessionFactoryBean

Employee employee = hibernateTemplate.get(Employee.class, employeeId);
System.out.println(employee.getEmployeeId() + "\t" + employee.getEmployeeName());
employee.setEmailString(newEmail);

hibernateTemplate.update(employee);

Hibernate:

select
    employee0_.employee_id as employee1_0_0_,
    employee0_.email as email2_0_0_,
    employee0_.employee_name as employee3_0_0_,
    employee0_.gender as gender4_0_0_,
    employee0_.salary as salary5_0_0_ 
from
    employee_details employee0_ 
where
    employee0_.employee_id=?

Only get is executing and the update query is not executing. Any idea why?

If you are using spring framework check you have applied @transactional. Otherwise you tell complete description which framework you are using.Just check your configuration is proper?

Could be an Hibernate or Spring transactionality configuration problem. Probally the changes has made in memory but not move to database.

To force this you can use

hibernateTemplate.flush();

BUT my advice is you work in the configuration of your system. This solution is a patch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM