简体   繁体   English

Hibernate4更新不起作用-LocalSessionFactoryBean

[英]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. get正在执行,而update查询未在执行。 Any idea why? 知道为什么吗?

If you are using spring framework check you have applied @transactional. 如果您使用的是Spring框架,请检查您是否已应用@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. 可能是Hibernate或Spring事务性配置问题。 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. 此解决方案是一个补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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