Hello
I have two entities, Kurs and ParameterRef with a @OneToMany relation:
@Entity @Table(name="KURS") public class Kurs {
@Id @Column(name = "KURS_ID", nullable = false) private Integer kursId;
...
@OneToMany(fetch=FetchType.LAZY, mappedBy = "kurs") private List<ParameterRef> parameterRefs = new ArrayList<ParameterRef>(); }
In a transaction I create and persist a Kurs object and then uses myNewKurs.getKursId() to create and persist a ParameterRef object. When this is done I use entityManager.find(Kurs.class, myNewKurs.getKursId()) to retreive a new updated Kurs instance with the parameterRefs-list updated and associated with my new created ParameterRef, but this fails when I am doing it in the same transaction used to create the new Kurs and ParameterRef objects and I only get a empty parameterRefs list.
If I let the transaction end and commit the changes and then use entityManager.find() in the same way i retrieve my Kurs object and a populated parameterRefs list containing my created ParameterRef. Is this the proper behaviour for hibernate? Can I have my new created Kurs-objekt updated within the transaction used to persist the enitity?
Regards Johan
|