I have the following setup
Class A:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
--> Set<B> bset;
Class B:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id;
What I do is:
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
A a = new A();
a.bset.add(new B());
manager.persist(a);
transaction.commit();
What happens is, that the id field of B is not updates (it is stored in the DB correctly).
When I use:
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
A a = new A();
B b = new B();
a.bset.add(b);
manager.persist(b);
manager.persist(a);
transaction.commit();
It works as expected and the id field is updated.
My Question is: Is this a bug or is it "to be expected" by the JPA spec?