In my project, I use hibernate and there is an object that has at least 30 references to other objects which are entities as well.
Of course it's not possible to just call
session.save(myHeavyObj);
Because it will throw "object references an unsaved transient instance".
I want to persist all objects. Is there any easy way to persist one object that contains many references to other entities objects?
UPDATE
@Entity
class MyClass{
//basic elements
@ElementCollection
@OneToMany(cascade=CascadeType.ALL) //some don't have this line
@LazyCollection(LazyCollectionOption.FALSE)
List<Medication> allMeds = new ArrayList<Medication>(); //Medication is Entity
//and more lists like this.
}
SOLUTION
It worked by adding
@OneToMany(cascade=CascadeType.ALL)