0
  • I have entity Patient and entity Test.
  • Both have ManyToMany relationships each other.
  • I added CASCADE_TYPE=ALL at both sides.
  • I am using Hibernate EntityManager's persist(Patient); method.
  • When i execute it it is throwing "org.hibernate.PersistentObjectException: detached entity passed to persist: Test"
  • These are the screens.

The Patient class Patient Class - Mapping

The Test class Test Class - Mapping

If anyone have solution please share it.

Thanks.

SteelToe
  • 2,477
  • 1
  • 17
  • 28

3 Answers3

0

thanks. i changed it to em.merge() from em.persist(). works fine.

0

merge and persist do pretty different things with your entity. Are you really sure that merge accomplishes what you intended to do in the first place ? (see this topic over here)

Without seeing the code that you wrote to persist the test - entity, I can't really tell you what went wrong, but I could imagine it having something to do with the manyToMany-relationships that you have there. Are you sure you want to cascade.ALL ? If you remove a test-instance from the database, the cascade will remove every patient in that list. And then, for every patient in that list, it will cascade.REMOVE every test in the List<test>.

Community
  • 1
  • 1
Christian W
  • 1,396
  • 1
  • 12
  • 17
-1

I suggest try to modify CASCADE_TYPE=PERSIST.

lenzhao
  • 1
  • 1