【发布时间】:2020-08-22 19:52:25
【问题描述】:
以前我没有收到任何错误,但突然我开始收到错误:
javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [baag.betl.dbimporter.esmatrans.db.EquSecurityReferenceData#baag.db.SECU@59c70ceb]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:116) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:787) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:765) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
没有为 oracle 数据库表中的任何列创建序列。还有 esn 和 techid 的唯一键列的组合。我不想在我的数据库表中创建新的序列列。
我认为我不能使用 @GeneratedValue 并将其设置为 Auto 用于唯一列,否则我会收到休眠序列错误。
我也在每处理 1000 条记录后进行清除和刷新。
if (secuData != null) {
sessionFactory.getCurrentSession().persist(secuData);
}
i++;
if (i % 1000 == 0) {
sessionFactory.getCurrentSession().flush();
sessionFactory.getCurrentSession().clear();
}
【问题讨论】:
标签: java spring hibernate exception sequence