• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

detached entity passed to persist

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 entities user, patient and doctor. Every doctor or patient is a user. I don't use inheritance strategy because I couldn't get an answer from my question here: Previous Problem

Now I'm trying to achieve a similar point without inheritance. Schema is like that:
User <--- OneToOne --> Doctor
User <--- OneToOne --> Patient
Patient <--- ManyToMany --> Doctor

My entities:
User.java:


Patient.java:


Doctor.java:


I've written junit tests for these entities. The doctor methods are working but patients' not.
This one creates 3 users(2 for patients 1 for doctor), 2 patients and a doctor.
DoctorTest.java:


But that one doesn't work as I expect:

PatientTest.java:


The for loop inside testCreatePatient executes up to unitNumber. When i becomes unitNumber + 1 (I mean 21), I'm getting detached entity passed to persist: tr.com.stigma.db.entity.User. It creates 20 doctors, 20 patients and 40 users until i gets to 20. At the 21st insert, I try to add a new patient to an existing doctor, consequently to an existing user. How can I do this?

Stack trace is here:
 
Gokcen Guner
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although nobody replied, I solved it.
I changed @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }) to @ManyToMany(cascade = { CascadeType.ALL })

 
This tiny ad is guaranteed to be gluten free.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic