Community
Participate
Working Groups
Build Identifier: EclipseLink, version: Eclipse Persistence Services - 2.1.2.v20101206 Using a native query that performs a delete the code throws the following validation exception: [junit] Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.ValidationException [junit] Exception Description: The attribute [AL_ID] of class [oracle.documaker.config.jpa.ALConfigContext] is mapped to a primary key column in the database. Updates are not allowed. Basically, I have a JPAConfiguration class that get called from a JUnit test case which call removePropertyList and causes the exception. I am providing the following files: stacktrace.txt - contains the entire stack trace. JPAConfiguration.java - contains all the code for removePropertyList. ALConfigurationContext.java - this is the entity class. persistence.xml Test case. Reproducible: Always Steps to Reproduce: 1. Run Ant from Documaker-Config directory. 2. Run the following command from Documaker-Config directory: ant test -Dtestcase=oracle.documaker.junit.JPAConfiguration_Oracle_Test 3.
Created attachment 186504 [details] Test Case test Case. 1 - Look at the build.xml in Documaker-Config and download / add the missing jar files: eclipselink.jar javax.peristence*.jar jaxb-api.jar jaxb-impl.jar get the following jar files from a tomcat6 implementation: tomcat-juli.jar bootstrap.jar catalina.jar put all the jars above in 3rparty_jars directory. 1 - Run ant from Documaker-Config directory. 2 - Run ant test -Dtestcase=oracle.documaker.junit.JPAConfiguration_Oracle_Test from Documaker-Config directory. You will see the error then. BTW, I couldn't include the jars above because of your attachment limit size.
You will also need to create junit-data and junit-report subdirectories under Documaker-Config directory. This is because I had to remove a bunch of stuff because of your attachment limit and missed this ones.
Created attachment 186507 [details] Missing log4j_console.xml file that goes in resources subdirectory Add the file to resources subdirectory.
You will also need ojdbc6.jar and commons-pool-1.5.5.jar.
Created attachment 186537 [details] Script to create the tables in the Oracle 11g Database The zip file contains the scripts to create the tables and import the data. The main tables of concern here are the SYSCONFIGCONTEXT, ALCONFIGCONTEXT and APPCONFIGCONTEXT tables. The stackTrace.txt file is also included which shows the logging at FINEST as well as the stack trace.
The data and table defined does not match what you have defined in your Entities for the primary key. ALCONFIGCONTEXT has ("CTX_ID", "AL_ID", "SYS_ID") as the pk, but the Entity has (SYS_ID;GROUP_NAME;AL_ID;PROPERTY) defined, and from the data provided, these are clearly not unique, as the first 6 rows inserted in the script are essentially the same entity. Looking quickly at the data, CTX_ID appears unique and a potential candidate for a primary key on its own (it is using a trigger to set a value from a sequence). Any reason why you are not just setting this field alone as the pk, and using a sequence generator in JPA instead of a trigger? Doing so will resolve your issue, as this invalid primary key is resulting in the cache becoming invalid - resulting in merges overwriting data on the same entity over and over. As the test case is calling em.persist before attempting the delete, this is causing the EntityManager cache of managed entities to become corrupted. Once corrupt, the subsequent flush (caused by your delete query) will find entities that it believes have been modified. You can verify by calling flush before the delete query - you will get the same exeption, showing it is not related to the delete operation. This is not an issue if a primary key is chosen that can uniquely identify the JPA entity.
Hi Chris, I want to thank you for your time and effort in this issue. After reading your last response and making some changes based on your comments I was able to get this working: I basically did this in AlConfigContext entity class: @Column(name="CTX_ID") @SequenceGenerator(name="AL_Gen", sequenceName="ALCONFIGCONTEXT_CTX_ID_SEQ", allocationSize=1) @Id @GeneratedValue(generator="AL_Gen") private int CTX_ID; I then made sure there is database sequence named ALCONFIGCONTEXT_CTX_ID_SEQ. I removed em.clear() prior to the delete. Everything works...:) Many, many thanks. BTW, the reason I left the PROPERTY and GROUP_NAME defined as @ID in the same AlConfigContext entity is that I noticed that if I don't do that all internal queries skip PROPERTY and GROUP_NAME and I need to make sure they are included. Is there another annotation that indicates, use a column in all queries but it is not an ID or part of a PK? Joe
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink