Skip to main content


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 10:51 Go to next message
Christoph Laeubrich is currently offline Christoph LaeubrichFriend
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?
Re: ID of referenced Entity is not updated with CascadeType.ALL [message #757809 is a reply to message #757250] Mon, 21 November 2011 18:46 Go to previous message
James Sutherland is currently offline James SutherlandFriend
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: Thu Mar 28 23:42:46 GMT 2024

Powered by FUDForum. Page generated in 0.04146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top