Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ID of referenced Entity is not updated with CascadeType.ALL
icon5.gif  ID of referenced Entity is not updated with CascadeType.ALL [message #757250] Thu, 17 November 2011 05:51 Go to next message
laeubi is currently offline laeubi
Messages: 6
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?
Re: ID of referenced Entity is not updated with CascadeType.ALL [message #757809 is a reply to message #757250] Mon, 21 November 2011 13:46 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Both should update the id in the object with what is persisted.

Do you some how get two copies of the B object?

How are you verifying the id was not set?


James : Wiki : Book : Blog : Twitter
Previous Topic:Re: Freeze after Exception
Next Topic:Re: ID of referenced Entity is not updated with CascadeType.ALL
Goto Forum:
  


Current Time: Fri Aug 29 08:28:31 EDT 2014

Powered by FUDForum. Page generated in 0.01502 seconds