简体   繁体   English

Hibernate 断言失败

[英]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.

相关问题 Hibernate AssertionFailure在不同的线程中 - Hibernate AssertionFailure in different Threads Spring3 /休眠声明失败 - Spring3/Hibernate AssertionFailure org.hibernate.AssertionFailure:可能对会话进行非线程安全的访问 - org.hibernate.AssertionFailure: possible non-threadsafe access to the session org.hibernate.AssertionFailure 获取序列值时的问题 - org.hibernate.AssertionFailure Issue when getting sequence value AssertionFailure:当Hibernate查询对象时,有时会抛出null id - AssertionFailure: null id sometimes thrown when Hibernate query objects org.hibernate.AssertionFailure: null 标识符@OneToOne 关系 - org.hibernate.AssertionFailure: null identifier @OneToOne relationship org.hibernate.AssertionFailure:集合被flush()处理了两次 - org.hibernate.AssertionFailure: collection was processed twice by flush() org.hibernate.criteria.uniqueResult期间的AssertionFailure - org.hibernate.AssertionFailure during criteria.uniqueResult Hibernate:org.hibernate.AssertionFailure:com.xxx.Bean条目中的null id - Hibernate: org.hibernate.AssertionFailure: null id in com.xxx.Bean entry 将MariaDB与Hibernate Filter结合使用时,如何获取AssertionFailure'找不到表'的根本原因? - How to get root cause of AssertionFailure 'Table not found' when using MariaDB with Hibernate Filter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM