jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常

jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常

 

  发生这个原因是因为我们已经在实体类用JPA注解指定了主键的生成策略主键就不能设置了,一旦不为空或者0就被认为是已经保存到了数据库中,一旦调用persist()方法就会抛出上面的异常

jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常

  把0去掉,如下图:

jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常

 

  

 

相关文章:

  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-12-09
  • 2022-02-25
  • 2021-04-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案