Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA - problem with merge

689823Mar 12 2009 — edited Mar 12 2009
Hi, I'm currently trying to port a very simple test project from glassfish to weblogic.

Everything works except one thing unfortunately. I'm using JPA with Toplink Essentials and in the data access layer, I use the entity manager's merge to persist changes.

em.merge(team);

In glassfish this line of code is all that is required (as well as error handling etc removed for brevity) but in weblogic I receive the following error:

org.apache.openjpa.lib.jdbc.ReportingSQLException: ORA-00001: unique constraint (TEST.SYS_C002408) violated
{prepstmnt 49 INSERT INTO TEAM (TEAM_ID, TEAM_NAME) VALUES (?, ?) [params=(String) T0000009, (String) Test]} [code=1, state=23000]


On further investigation it turns out that this is because the entity I was trying to merge didn't currently exist in the PersistenceContext and so instead of merging, instead it tried to persist a new record to the database which would then break the unique constraint.

As a solution, it was suggested to turn the update function into the following:

em.find(Team.class, team.getTeamID());
em.merge(team);

As now, before trying to merge, the correct entity would be placed in the PersistenceContext and the merge could take place. Unfortunately this led to the following error:

javax.ejb.EJBTransactionRolledbackException: EJB Exception: ; nested exception is: <openjpa-1.1.0-r422266:657916 nonfatal store error> org.apache.openjpa.persistence.EntityExistsException: An object of type "jpaTest.Team" with oid "T0000009" already exists in this context; another cannot be persisted.


It makes no sense. There are errors whether the entity exists in the PersistenceContext or not. Can anyone help? Like I say in glassfish this just 'works' and i'm using the exact same libraries etc.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2009
Added on Mar 12 2009
1 comment
1,737 views