ID of referenced Entity is not updated with CascadeType.ALL [message #757999] |
Thu, 17 November 2011 10:51 |
Christoph Laeubrich Messages: 12 Registered: September 2011 |
Junior Member |
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.06538 seconds