简体   繁体   English

休眠列表()抛出 EntityNotFoundException

[英]Hibernate list() throws EntityNotFoundException

We got recently problem in production:我们最近在生产中遇到了问题:

healthcheck involves db query - list() is called on table B simple select, Table A is not related to table B at all.健康检查涉及数据库查询 - 在表 B 上调用 list() 简单选择,表 A 与表 B 根本不相关。 And it is always same A row which is not found, over and over.它总是相同的 A 行,一遍又一遍地找不到。 It seems somewhere is a global state.似乎某处是一个全局状态。

we are not using L2 cache.我们没有使用 L2 缓存。

Caused by: javax.persistence.EntityNotFoundException: No row with the given identifier exists: [**org.xxx.A#bqdsDYEVRRoUjGET**]
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:113)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1423)
    at org.hibernate.query.internal.AbstractProducedQuery.uniqueResult(AbstractProducedQuery.java:1457)

Hibernate version:休眠版本:

5.2.12.Final

I found the problem.我发现了问题。 I am using PlatformTransactionManager to manage transactions.我正在使用 PlatformTransactionManager 来管理事务。 For read operations it was something like对于读取操作,它类似于

try {
  transactionManager.getTransaction();
  readOperations();
  transactionManager.commit();
} catch (Exception e) {
  log(e);
}

In edge cases if graph of objects is deleted in separate transaction, readOperations() failes with EntityNotFoundException, transaction is never rollbacked or commited.在边缘情况下,如果对象图在单独的事务中被删除,则 readOperations() 因 EntityNotFoundException 而失败,事务永远不会回滚或提交。 Spring HibernateTransactionManager stores Sessions+Transaction in ThreadLocal, so its never cleaned up, thread continue using same Session object. Spring HibernateTransactionManager 将 Sessions+Transaction 存储在 ThreadLocal 中,因此它永远不会被清理,线程继续使用相同的 Session 对象。 Next request served by this thread cause Session+Transaction flushing previous unsuccsessful DML and we got repetitive failures.此线程提供的下一个请求导致 Session+Transaction 刷新之前不成功的 DML,我们得到了重复的失败。

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

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