我们有一个Java后端应用程序(使用Java 9创建),并且当前在通过Hibernate插入表记录时遇到此问题。
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist:
问题是,这仅在UAT环境中插入到我们的表中时发生。在SIT和DEV数据库中进行相同的插入时,不会发生这种情况。我们已经验证了UAT和SIT / DEV中的代码相同,并且还验证了表结构是否相同。还有什么可能导致此异常?
以下是我们使用的实体类的代码段:
@Entity
@Table(name = "SOME_TABLE")
public class SomeTable {
@Id
@Column(name = "SOME_TABLE_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "someTableSeq")
@SequenceGenerator(name = "someTableSeq", sequenceName = "SOME_TABLE_SEQ",
allocationSize = 1)
private Long id;
@Column(name = "FIELD_ONE")
private String fieldOne;
@Column(name = "FIELD_TWO")
private String fieldTwo;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_DT")
private Date createdDt;
Settings:
hibernate-core version: 5.2.10
hibernate-jpa version: 2.1
spring: 4.3.0-RELEASE
Database: Oracle 12c