| Record persist order [message #524841] |
Fri, 02 April 2010 17:45  |
John Lister 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();
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  |
James Sutherland Messages: 1844 Registered: July 2009 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.01509 seconds