Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Record persist order
Record persist order [message #524841] Fri, 02 April 2010 17:45 Go to next message
Eclipse UserFriend
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();
em.persist(user);
Profile profile=new Profile(user.getID());
em.persist(profile);

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?

Thanks

John
Re: Record persist order [message #525413 is a reply to message #524841] Tue, 06 April 2010 10:22 Go to previous message
Eclipse UserFriend
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.

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: Sun Jul 27 06:37:48 EDT 2025

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

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

Back to the top