Hibernate - 查询为实体中的所有字段返回null
Long fooId = 39;
Query query = getCurrentSession().createQuery("from FooEntity where deleted IS FALSE AND id=:fooId" );
query.setParameter( "fooId", fooId );
FooEntity fooEntity = ( FooEntity ) query.uniqueResult();
检查 FooEntity 显示以下结果
(id=null, name=null, deleted=null)
虽然相同的查询从 db 返回完美的结果
select * from foo where deleted IS FALSE AND id=39
(id, name, deleted) => (39, 'Bar', false)
必须注意的是,这仅在随机情况下发生。大多数时候 hibernate 会返回完美的结果。
最佳答案
请尝试log
或sysout
下一行中的值。
对于我和 OP问题是一样的,只是 Java Debugger 没有显示值。值(value)始终存在。
关于java - Hibernate - 查询为实体中的所有字段返回空值,而同一查询从数据库中完美返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28477226/