Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Record persist order
Record persist order [message #524841] Fri, 02 April 2010 21:45 Go to next message
John Lister is currently offline John ListerFriend
Messages: 3
Registered: April 2010
Junior Member
Hi, I'm using eclipselink within glassfish v3 and have a question about persisting records with foreign key relationships. I used to use topLink and currently switching to eclipselink so I'm sure this used to work before, anyway the problem:

I have 2 tables user and profile of which profile has a 1-1 mapping to the user. Currently I don't have the relationship defined within the entity classes and I'm trying to persist new entities, except I have a problem.

I'm doing
User user=new User();
Profile profile=new Profile(user.getID());

within toplink I'm sure this would work as it would execute the insert statements on the database in the order give above. However eclipselink is trying to insert the profile first which fails as the foreign key is violated because the user hasn't been inserted.

Is this expected, can I change the order or would adding a relationship within the entities fix it?


Re: Record persist order [message #525413 is a reply to message #524841] Tue, 06 April 2010 14:22 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You should have had the same issue with TopLink, unless you were using the insertObject API directly.

You need to either add the relationships, or on the ClassDescriptor define the constraint dependency (addConstraintDependency()) (you can use a DescriptorCustomizer to call this).

You could also call flush() after persisting the User.

James : Wiki : Book : Blog : Twitter
Previous Topic:Set join column to null after removing the related row?
Next Topic:Cannot merge entity when there is other entity extends
Goto Forum:

Current Time: Mon May 28 01:34:55 GMT 2018

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

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

Back to the top