merge « Glassfish « JPA Q&A

1. ID value already provided when calling merge with OpenJPA and WebSphere 7

Some basic information:

  • WebSphere (with JPA 2.0 fix)
  • OpenJPA 2.0.1
  • Spring 3.0.5
  • SQL Server 2008
I have an entity as follows:
public class QuestionnaireClient {

/* --- Members --- */

/** The unique, internal ID of the entity. ...

2. JPA merge specification

"If X is an entity merged to X', with a reference to another entity Y, where cascade=MERGE or cascade=ALL is not specified, then navigation of the same association from X' yields a reference to a managed object Y' with the same persistent identity as Y."OK, but what state (the values of the persistent field) for Y' ?

3. JPA Merge and Remove

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b45-beta3 (05/03/2007))): oracle.toplink.essentials.exceptions.DatabaseException Internal Exception: java.sql.SQLIntegrityConstraintViolationException: DELETE on table 'VEHICLE' caused a violation of foreign key constraint 'BSCDTTRGTCPLCPLNGD' for key (202). The statement has been rolled back. Error Code: 20000 Call: DELETE FROM VEHICLE WHERE (VEHICLEID = ?) bind => [202] Query: DeleteObjectQuery(Vehicle Car) oracle.toplink.essentials.exceptions.DatabaseException.sqlException( oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect( oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeNoSelect( ... MainProgramManagement.ProgramMain.removeData(

4. JPA merge creating new record

Now, I have read that if the EntityManager does not have track of an entity with the given ID, it will create a new one. So, thinking that this in-and-out-of-hashtable operation might cause the EM to lose track of the entities (for some reason), I've created a simple test program as well, to ensure the EntityManager DOES know about an entity. ...