[英]Hibernate AssertionFailure
When I try to save a new entity to the database, I have the following error:当我尝试将新实体保存到数据库时,出现以下错误:
org.hibernate.AssertionFailure: null id in xxx.nameBean entry (don't flush the Session after an exception occurs)
produced at the code在代码处产生
session.save(nameBean)
but, "magically" it only appears at Production Server.但是,“神奇地”它只出现在生产服务器上。 When I try to reproduce the error at localhost, with the same code and data (using copy of the DB of Production Server, via bak file) it works ok.
当我尝试使用相同的代码和数据(使用生产服务器数据库的副本,通过 bak 文件)在本地主机上重现错误时,它可以正常工作。
What can it be?会是什么?
EDIT: Adding the code that probably cause the error.编辑:添加可能导致错误的代码。 The objective of that code is save the bean and update the otherBean in the same transaction, so if something wrong ocurrs make the rollback.
该代码的目标是保存 bean 并在同一事务中更新 otherBean,因此如果出现错误,则进行回滚。
public class BeanDao extends ManagedSession {
public Integer save(Bean bean) {
Session session = null;
try {
session = createNewSessionAndTransaction();
Integer idValoracio = (Integer) session.save(bean);
doOtherAction(bean);
commitTransaction(session);
return idBean;
} catch (RuntimeException re) {
log.error("get failed", re);
if (session != null) {
rollbackTransaction(session);
}
throw re;
}
}
private void doOtherAction(Bean bean) {
Integer idOtherBean = bean.getIdOtherBean();
OtherBeanDao otherBeanDao = new OtherBeanDao();
OtherBean otherBean = otherBeanDao.findById(idOtherBean);
.
.
.
otherBeanDao.attachDirty(otherBean)
}
}
As the error message says, it's probably caused by attempt to use a session after it thrown an exception.正如错误消息所说,它可能是由于在抛出异常后尝试使用 session 引起的。 Make sure your code doesn't swallow any Hibernate exceptions.
确保您的代码不会吞下任何 Hibernate 异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.