我的数据库中有一张带有主组合键的表,当我使用 Hibernate 对其进行建模时,我使用@EmbeddedId& @Embedable。该复合主键的一列具有带有 的生成值@GeneratedValue(strategy = GenerationType.IDENTITY)。
当我尝试在数据库中创建两个新对象时,出现如下错误:
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [MyPackage#MyEmbedableClass [MyGeneratedPrimaryKeyValue=null, OtherPrimaryKey=21]]
Run Code Online (Sandbox Code Playgroud)
但是当我查看数据库时,我的对象已创建。我不明白我的错误,我不知道如何解决我的问题。
我找到了一些像我这样的主题,但还没有找到我的问题的答案。
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [MyPackage#MyEmbedableClass [MyGeneratedPrimaryKeyValue=null, OtherPrimaryKey=21]]
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。