Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Error During Delete: is mapped to a primary key column in the database. Updates are not allowed.(Error during delete: is mapped to a primary key column in the database. Updates are not allowed.)
Error During Delete: is mapped to a primary key column in the database. Updates are not allowed. [message #647969] Mon, 10 January 2011 16:10 Go to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
I am getting this error during a delete:


[junit] [EL Finest]: 2011-01-10 11:00:23.078--UnitOfWork(1635615)--Thread(Thread[main,5,main ])--Execute query UpdateObjectQuery(oracle.documaker.config.jpa.ALConfigCo
ntext[SYS_ID=1, AL_ID=1, GROUP_NAME=TestGroup, PROPERTY=TestProperty, VALUE=456])
[junit] [EL Warning]: 2011-01-10 11:00:23.093--UnitOfWork(1635615)--Thread(Thread[main,5,main ])--Local Exception Stack:
[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.

Here is the code, the error is thrown in the commit line. I am trying to set the value for SYS_ID and AL_ID which are keys but I am doing this because I only want to delete the records that match the SYS_ID, AL_ID, GROUP_NAME and PROPERTY.

em.getTransaction().begin();
ALConfigContext alContext = new ALConfigContext();
alContext.setSYS_ID(sysId);
alContext.setAL_ID(alId);
alContext.setGROUP_NAME(group);
if (Data.isValidString(property)){
alContext.setPROPERTY(property);
}
alContext = em.merge(alContext);
em.remove(alContext);
em.flush();
em.getTransaction().commit();

What is it I have to do to avoid this error? BTW, I also receive the same error when I try to use a "DELETE FROM" statement in a native query. As far as I know a delete should not be updating any keys so why is this error being thrown? Is it a bug?

I am using these jar files downloaded on 1/10/2011:

javax.persistence_2.0.1.v201006031150.jar
eclipselink_2.1.2.jar

Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #647970 is a reply to message #647969] Mon, 10 January 2011 16:12 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
BTW, a simple JDBC delete would have taken me 30 minutes to write and test. So far I have spend almost a day trying to figure this out. Why is JPA so complicated?
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #647988 is a reply to message #647969] Mon, 10 January 2011 17:16 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Not sure I understand what you are trying to do.

What is the Id of ALConfigContext?

You should not be using merge() in this way, merge() is for updating an object with changes from a serialized or detached copy of that object, you just seem to want to delete the object, not update it.

To delete and object, assuming the Id is sysId, you just need to do,


em.getTransaction().begin();
ALConfigContext alContext = em.find(ALConfigContext.class, sysId);
em.remove(alContext);
em.getTransaction().commit();

If you are trying to delete a set of objects, you need to first query the set of objects using a Query, then loop over them and delete them one by one.

Or, if you do not wish to load them, you could use a delete all Query or even a native SQL query.

em.getTransaction().begin();
Query query = em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group");
query.setParameter("sysId", sysId);
query.setParameter("alId", alId );
query.setParameter("group", group);
query.executeUpdate();
em.getTransaction().commit();


James : Wiki : Book : Blog : Twitter

[Updated on: Mon, 10 January 2011 17:17]

Report message to a moderator

Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648012 is a reply to message #647969] Mon, 10 January 2011 19:45 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
Hi James,

I am trying to delete all records that match SYS_ID, AL_ID, GROUP_NAME and PROPERTY.

I can try to do a find and see if that helps. When I tried to do a remove without the merge it actually told me I coudln't do that operation on a detached record, hence I added the merge. Perhaps the find will help. BTW, When I also tried the SQL below through a native query and query.executeUpdate() call, I received the same exact error.

DELETE FROM ALCONFIGCONTEXT where SYS_ID=? and AL_ID=? and GROUP_NAME=? and PROPERTY=?

It seems strange to me that the same error would be issued for a native query with the SQL above as I am obviously not trying to update AL_ID?
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648013 is a reply to message #648012] Mon, 10 January 2011 19:48 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
BTW, I have also tried this before and got the same error:

em.getTransaction().begin();
Query query = em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group");
query.setParameter("sysId", sysId);
query.setParameter("alId", alId );
query.setParameter("group", group);
query.executeUpdate();
em.getTransaction().commit();
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648017 is a reply to message #648012] Mon, 10 January 2011 20:59 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
OK,

using find instead of merge does not work for me because I need to match all records with the same SYS_ID, AL_ID, GROUP_NAME and PROPERTY and find only takes the class and a string for the primary key. I am not sure how I am supposed to use find in this case: Perhaps creating a string that concatenates SYS_ID, AL_ID, GROUP_NAME and PROPERTY and pass that as the primary key second argument to find?

As far as using a native query goes: I just tried again and I got the same error as before:


[junit] 2011-01-10 15:49:01,968-[main]-DEBUG-JPAConfiguration-removePropertyLis t: removePropertyList(TestGroup, TestProperty)
[junit] [EL Finer]: 2011-01-10 15:49:01.968--ClientSession(11328770)--Connection(8550760)-- Thread(Thread[main,5,main])--begin transaction
[junit] [EL Finest]: 2011-01-10 15:49:01.968--ClientSession(11328770)--Thread(Thread[main,5, main])--reconnecting to external connection pool
[junit] [EL Finest]: 2011-01-10 15:49:01.968--UnitOfWork(8703610)--Thread(Thread[main,5,main ])--Execute query UpdateObjectQuery(oracle.documaker.config.jpa.ALConfigCo
ntext[SYS_ID=1, AL_ID=1, GROUP_NAME=TestGroup, PROPERTY=TestProperty, VALUE=123])
[junit] [EL Warning]: 2011-01-10 15:49:02.093--UnitOfWork(8703610)--Thread(Thread[main,5,main ])--Local Exception Stack:
[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.
[junit] at org.eclipse.persistence.exceptions.ValidationException.prima ryKeyUpdateDisallowed(ValidationException.java:2452)
[junit] at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectM apping.java:1320)
[junit] at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildRowForUpdateWithChangeSet(ObjectBuilder.java:1140)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism .java:1111)
[junit] at org.eclipse.persistence.queries.UpdateObjectQuery.executeCom mitWithChangeSet(UpdateObjectQuery.java:84)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:29 0)
[junit] at org.eclipse.persistence.queries.WriteObjectQuery.executeData baseQuery(WriteObjectQuery.java:58)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:740)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:643)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery. java:108)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWork(ObjectLevelModifyQuery.java:85)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2908)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1291)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1273)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1233)
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itChangedObjectsForClassWithChangeSet(CommitManager.java:265 )
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itAllObjectsWithChangeSet(CommitManager.java:128)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.wr iteAllObjectsWithChangeSet(AbstractSession.java:3348)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabase(UnitOfWorkImpl.java:1422)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:610)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1568)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.writeChanges(RepeatableWriteUnitOfWork.java:423)
[junit] at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush (EntityManagerImpl.java:741)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.performPre QueryFlush(EJBQueryImpl.java:1237)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeUpd ate(EJBQueryImpl.java:532)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removeJPAListFo r(JPAConfiguration.java:600)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removePropertyL ist(JPAConfiguration.java:456)
[junit] at oracle.documaker.junit.JPAConfiguration_Oracle_Test.JPAConfi guration_Oracle_Test_testSetPropertyList(JPAConfiguration_Or acle_Test.java:354)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:597)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:76)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:50)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java :39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .run(JUnitTestRunner.java:422)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .launch(JUnitTestRunner.java:931)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .main(JUnitTestRunner.java:785)
[junit]
[junit] 2011-01-10 15:49:02,156-[main]-ERROR-JPAConfiguration-removeJPAListFor: javax.persistence.PersistenceException: Exception [EclipseLink-7251] (Eclipse Persist
ence 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.
[junit] at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush (EntityManagerImpl.java:744)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.performPre QueryFlush(EJBQueryImpl.java:1237)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeUpd ate(EJBQueryImpl.java:532)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removeJPAListFo r(JPAConfiguration.java:600)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removePropertyL ist(JPAConfiguration.java:456)
[junit] at oracle.documaker.junit.JPAConfiguration_Oracle_Test.JPAConfi guration_Oracle_Test_testSetPropertyList(JPAConfiguration_Or acle_Test.java:354)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:597)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:76)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:50)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java :39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .run(JUnitTestRunner.java:422)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .launch(JUnitTestRunner.java:931)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .main(JUnitTestRunner.java:785)
[junit] Caused by: 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.
[junit] at org.eclipse.persistence.exceptions.ValidationException.prima ryKeyUpdateDisallowed(ValidationException.java:2452)
[junit] at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectM apping.java:1320)
[junit] at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildRowForUpdateWithChangeSet(ObjectBuilder.java:1140)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism .java:1111)
[junit] at org.eclipse.persistence.queries.UpdateObjectQuery.executeCom mitWithChangeSet(UpdateObjectQuery.java:84)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:29 0)
[junit] at org.eclipse.persistence.queries.WriteObjectQuery.executeData baseQuery(WriteObjectQuery.java:58)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:740)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:643)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery. java:108)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWork(ObjectLevelModifyQuery.java:85)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2908)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1291)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1273)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1233)
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itChangedObjectsForClassWithChangeSet(CommitManager.java:265 )
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itAllObjectsWithChangeSet(CommitManager.java:128)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.wr iteAllObjectsWithChangeSet(AbstractSession.java:3348)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabase(UnitOfWorkImpl.java:1422)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:610)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1568)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.writeChanges(RepeatableWriteUnitOfWork.java:423)
[junit] at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush (EntityManagerImpl.java:741)
[junit] ... 29 more
[junit]
[junit] ------------- ---------------- ---------------
[junit] ------------- Standard Error -----------------
[junit] log4j:WARN No appenders could be found for logger (oracle.documaker.junit.Util).
[junit] log4j:WARN Please initialize the log4j system properly.
[junit] ------------- ---------------- ---------------
[junit]
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperty_System took 0.484 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperty_AssemblyLine took 0.203 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperty_Application took 0.219 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperties_System took 1.11 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperties_AssemblyLine took 0.407 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetProperties_Application took 0.312 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertyValueFor_System took 0.203 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertyValueFor_Assembl yLine took 0.266 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertyValueFor_Applica tion took 0.187 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertiesFor_System took 0.157 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertiesFor_AssemblyLi ne took 0.203 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertiesFor_Applicatio n took 0.109 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testGetPropertyListFor took 1.531 sec
[junit] Testcase: JPAConfiguration_Oracle_Test_testSetPropertyList took 1.141 sec
[junit] FAILED
[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.
[junit] junit.framework.AssertionFailedError: 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.
[junit] at oracle.documaker.junit.JPAConfiguration_Oracle_Test.JPAConfi guration_Oracle_Test_testSetPropertyList(JPAConfiguration_Or acle_Test.java:356)
[junit]
[junit] Test oracle.documaker.junit.JPAConfiguration_Oracle_Test FAILED
[junitreport] Processing c:\rel121\DocumentFactory\Documaker-Config\junit-data\TESTS- TestSuites.xml to d:\temp\null65411212
[junitreport] Loading stylesheet jar:file:/C:/java/apache-ant-1.8.0/lib/ant-junit.jar!/org/ap ache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 515ms
[junitreport] Deleting: d:\temp\null65411212

BUILD FAILED
c:\rel121\DocumentFactory\Documaker-Config\build.xml:269: Tests failed. Check log(s) and/or report(s).

Total time: 21 seconds
c:\rel121\DocumentFactory\Documaker-Config>



Here is the code:

private void removeJPAListFor(String group,
String property)throws Exception{
if (em == null ||
!Data.isValidString(group)){
return;
}

try{
Query query = getDeleteQueryFor(group, property);
em.getTransaction().begin();
int count = query.executeUpdate();
em.getTransaction().commit();
}catch(Exception e){
log.error(IO.stackTrace(e));
throw e;
}

}

private Query getDeleteQueryFor(String group, String property){

Query query = null;
if (em == null ||
!Data.isValidString(group)){
return query;
}

switch(getConfigurationType()){
case SYS_TYPE:{
query = property == null? em.createNativeQuery("DELETE from SysConfigContext sys where sys.SYS_ID=? and sys.GROUP_NAME=?") :
em.createNativeQuery("DELETE from SysConfigContext sys where sys.SYS_ID=? and sys.GROUP_NAME=? and sys.PROPERTY=?");
query.setParameter(1, sysId);
query.setParameter(2, group);
if (property != null){
query.setParameter(3, property);
}else{
query.setParameter(3, 1);
}
break;
}case AL_TYPE:{
query = property == null? em.createNativeQuery("DELETE from ALConfigContext al where al.SYS_ID=? and al.AL_ID=? and al.GROUP_NAME=?") :
em.createNativeQuery("DELETE from ALConfigContext al where al.SYS_ID=? and al.AL_ID=? and al.GROUP_NAME=? and al.PROPERTY=?");
query.setParameter(1, sysId);
query.setParameter(2, alId);
query.setParameter(3, group);
if (property != null){
query.setParameter(4, property);
}else{
query.setParameter(4, 1);
}
break;
}case APP_TYPE:{
query = property == null? em.createNativeQuery("DELETE from AppConfigContext app where app.SYS_ID=? and app.AL_ID=? and app.APP_ID=? and app.GROUP_NAME=?") :
em.createNativeQuery("DELETE from AppConfigContext app where app.SYS_ID=? and app.AL_ID=? and app.APP_ID=? and app.GROUP_NAME=? and app.PROPERTY=?");
query.setParameter(1, sysId);
query.setParameter(2, alId);
query.setParameter(3, appId);
query.setParameter(4, group);
if (property != null){
query.setParameter(5, property);
}else{
query.setParameter(5, 1);
}
break;
}default:
break;
}

return query;
}
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648018 is a reply to message #648017] Mon, 10 January 2011 21:01 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
BTW, removePropertyList, which was included in the last stack trace, calls the code that accompanies the last stack trace. Here is the actual code that shows that:

public void removePropertyList(String group, String property) throws Exception{
if (log.isDebugEnabled()){
log.debug("removePropertyList(" + group + ", " + property + ")");
}

if (!Data.isValidString(group) ||
!Data.isValidString(property)){
return;
}

removeJPAListFor(group,
property);

}
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648020 is a reply to message #648018] Mon, 10 January 2011 21:15 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
I also tried the your query and I get the same error:

Here is the code for your query (the code follows the case AL_TYPE):

private Query getDeleteQueryFor(String group, String property){

Query query = null;
if (em == null ||
!Data.isValidString(group)){
return query;
}

switch(getConfigurationType()){
case SYS_TYPE:{
query = property == null? em.createNativeQuery("DELETE from SysConfigContext sys where sys.SYS_ID=? and sys.GROUP_NAME=?") :
em.createNativeQuery("DELETE from SysConfigContext sys where sys.SYS_ID=? and sys.GROUP_NAME=? and sys.PROPERTY=?");
query.setParameter(1, sysId);
query.setParameter(2, group);
if (property != null){
query.setParameter(3, property);
}
break;
}case AL_TYPE:{
/*
* query = property == null? em.createNativeQuery("DELETE from ALConfigContext al where al.SYS_ID=? and al.AL_ID=? and al.GROUP_NAME=?") :
em.createNativeQuery("DELETE from ALConfigContext al where al.SYS_ID=? and al.AL_ID=? and al.GROUP_NAME=? and al.PROPERTY=?");
*/
query = property == null? em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group") :
em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group and c.PROPERTY=:property");
query.setParameter("sysId", sysId);
query.setParameter("alId", alId);
query.setParameter("group", group);
if (property != null){
query.setParameter("property", property);
}
break;
}case APP_TYPE:{
query = property == null? em.createNativeQuery("DELETE from AppConfigContext app where app.SYS_ID=? and app.AL_ID=? and app.APP_ID=? and app.GROUP_NAME=?") :
em.createNativeQuery("DELETE from AppConfigContext app where app.SYS_ID=? and app.AL_ID=? and app.APP_ID=? and app.GROUP_NAME=? and app.PROPERTY=?");
query.setParameter(1, sysId);
query.setParameter(2, alId);
query.setParameter(3, appId);
query.setParameter(4, group);
if (property != null){
query.setParameter(5, property);
}
break;
}default:
break;
}

return query;
}

Here is the error:

[junit] 2011-01-10 16:11:50,703-[main]-DEBUG-JPAConfiguration-getPropertyListFo r: Returning <[123]>.
[junit] 2011-01-10 16:11:50,703-[main]-DEBUG-JPAConfiguration-removePropertyLis t: removePropertyList(TestGroup, TestProperty)
[junit] [EL Finer]: 2011-01-10 16:11:51.265--ClientSession(2633821)--Connection(145238)--Th read(Thread[main,5,main])--begin transaction
[junit] [EL Finest]: 2011-01-10 16:11:51.265--ClientSession(2633821)--Thread(Thread[main,5,m ain])--reconnecting to external connection pool
[junit] [EL Finest]: 2011-01-10 16:11:51.265--UnitOfWork(24840600)--Thread(Thread[main,5,mai n])--Execute query UpdateObjectQuery(oracle.documaker.config.jpa.ALConfigC
ontext[SYS_ID=1, AL_ID=1, GROUP_NAME=TestGroup, PROPERTY=TestProperty, VALUE=678])
[junit] [EL Warning]: 2011-01-10 16:11:51.281--UnitOfWork(24840600)--Thread(Thread[main,5,mai n])--Local Exception Stack:
[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.
[junit] at org.eclipse.persistence.exceptions.ValidationException.prima ryKeyUpdateDisallowed(ValidationException.java:2452)
[junit] at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectM apping.java:1320)
[junit] at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildRowForUpdateWithChangeSet(ObjectBuilder.java:1140)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism .java:1111)
[junit] at org.eclipse.persistence.queries.UpdateObjectQuery.executeCom mitWithChangeSet(UpdateObjectQuery.java:84)
[junit] at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:29 0)
[junit] at org.eclipse.persistence.queries.WriteObjectQuery.executeData baseQuery(WriteObjectQuery.java:58)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:740)
[junit] at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:643)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery. java:108)
[junit] at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWork(ObjectLevelModifyQuery.java:85)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2908)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1291)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1273)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1233)
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itChangedObjectsForClassWithChangeSet(CommitManager.java:265 )
[junit] at org.eclipse.persistence.internal.sessions.CommitManager.comm itAllObjectsWithChangeSet(CommitManager.java:128)
[junit] at org.eclipse.persistence.internal.sessions.AbstractSession.wr iteAllObjectsWithChangeSet(AbstractSession.java:3348)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabase(UnitOfWorkImpl.java:1422)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:610)
[junit] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1568)
[junit] at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.writeChanges(RepeatableWriteUnitOfWork.java:423)
[junit] at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush (EntityManagerImpl.java:741)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.performPre QueryFlush(EJBQueryImpl.java:1237)
[junit] at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeUpd ate(EJBQueryImpl.java:532)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removeJPAListFo r(JPAConfiguration.java:600)
[junit] at oracle.documaker.config.jpa.JPAConfiguration.removePropertyL ist(JPAConfiguration.java:456)
[junit] at oracle.documaker.junit.JPAConfiguration_Oracle_Test.JPAConfi guration_Oracle_Test_testSetPropertyList(JPAConfiguration_Or acle_Test.java:354)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:597)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:76)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:50)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
[junit] at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java :39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .run(JUnitTestRunner.java:422)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .launch(JUnitTestRunner.java:931)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner .main(JUnitTestRunner.java:785)
[junit]


Is the error a bug? It seems deleting records is extremely complicated in EclipseLink.


Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648021 is a reply to message #648020] Mon, 10 January 2011 21:32 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
Also, If I am executing a delete and I am not providing any value for VALUE column, why is EclipseLink showing this when logging is set to FINEST?

[junit] 2011-01-10 16:31:31,171-[main]-DEBUG-JPAConfiguration-removePropertyLis t: removePropertyList(TestGroup, TestProperty)
[junit] [EL Finer]: 2011-01-10 16:31:31.187--ClientSession(11001145)--Connection(22892006)- -Thread(Thread[main,5,main])--begin transaction
[junit] [EL Finest]: 2011-01-10 16:31:31.187--ClientSession(11001145)--Thread(Thread[main,5, main])--reconnecting to external connection pool
[junit] [EL Finest]: 2011-01-10 16:31:31.187--UnitOfWork(1635615)--Thread(Thread[main,5,main ])--Execute query UpdateObjectQuery(oracle.documaker.config.jpa.ALConfigCo
ntext[SYS_ID=1, AL_ID=1, GROUP_NAME=TestGroup, PROPERTY=TestProperty, VALUE=123])
[junit] [EL Warning]: 2011-01-10 16:31:31.218--UnitOfWork(1635615)--Thread(Thread[main,5,main ])--Local Exception Stack:
[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.

Look at UpdateObjectQuery it has VALUE=123?

Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648023 is a reply to message #648021] Mon, 10 January 2011 21:35 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
Should UpdateObjectQuery even get called? I don't understand why when I am using the code I already pasted for a delete UpdateObjectQuery is getting called which includes the VALUE. It is almost as if the code is trying to update a record instead of deleting it.
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648152 is a reply to message #648023] Tue, 11 January 2011 14:06 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
I guess the lack of responses means I should write a bug, give up for now and just use JDBC?
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648166 is a reply to message #648152] Tue, 11 January 2011 14:43 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1035
Registered: July 2009
Senior Member
Hello Joe,

It looks like you are trying different things, and while this is good, it makes it difficult to respond to each of the 7 posts with details on why things might not be working as you expect. As James stated in his post, you should not be setting partial attributes on an entity and then calling merge and instead querying for the objects you want and then calling em.remove on them one by one. Find will only return the entity with that exact matching primary key. So you cannot use partical pks to return a group.

Instead, try a query such as
List entities = em.createQuery("Select c from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group").getResultList();
and then iterate over the list calling em.remove on each entity.

By calling merge, you are doing just that - the persistence provider must merge the state of the entity you created into the existing entity matching that ID. This, and any other changes you have made in the context to managed entities upto that point, causes hte update queries when flush is called, as these changes must be persisted to the database.

Your next posts seem to be attempts to use native SQL. I am not sure which queries are being done when the exception is occuring - number of possible code paths are given but not enough info on which path the code takes when the error occurs is given, or what else is done in the context. You might want to simplify your issue a bit and start up a new thread. Please also note that in the last thread you posted, the update is not happening on your flush call, but because flush is automatically called before each query (flush mode is set to auto instead of manual - it is configurable). This means that your executeUpdate call triggers a flush, and so managed entities have to have been changed for EclipseLink to attempt an update. This is not a clear persistence context.

Could it be you are using an extended persistence context that you are using to read entities and make changes before creating a transaction and attempting to delete?
If so, try calling em.clear().

Best Regards,
Chris
Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648197 is a reply to message #648166] Tue, 11 January 2011 18:18 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
Hi Chris,

Thank you for your response. I am only concerned with the native query delete at this point. Here is the code I am trying to execute right now (property is not null):

Query query = property == null? em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group") :
em.createQuery("Delete from ALConfigContext c where c.SYS_ID = :sysId and c.AL_ID = :alId and c.GROUP_NAME = :group and c.PROPERTY=:property");
query.setParameter("sysId", sysId);
query.setParameter("alId", alId);
query.setParameter("group", group);
if (property != null){
query.setParameter("property", property);

em.getTransaction().begin();
query.executeUpdate();
em.getTransaction().commit();

It is throwing this 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.

Questions:

Is possible to do a delete without having to call getResultList() as you suggested?


I am never closing the EntityManager instance. It is kept around and used from multiple functions that do inserts, (persists), merges, etc. Could this be the problem and perhaps not calling em.clear() is the problem?

BTW, I have created a bug for this and included a test case:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=333977

Thanks,

Joe





Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648337 is a reply to message #648197] Wed, 12 January 2011 13:49 Go to previous messageGo to next message
Joe Roberts is currently offline Joe Roberts
Messages: 24
Registered: July 2009
Junior Member
Well, using clear() works when I do this:

private void removeJPAListFor(String group,
String property)throws Exception{
if (em == null ||
!Data.isValidString(group)){
return;
}

try{
em.clear();
Query query = getDeleteQueryFor(group, property);
em.getTransaction().begin();
int count = query.executeUpdate();
em.getTransaction().commit();
if (log.isDebugEnabled()){
log.debug("*****count=<" + count + ">");
}

}catch(Exception e){
log.error(IO.stackTrace(e));
em.getTransaction().rollback();
throw e;
}

}

However I am not sure if it is just a bandaid?

Does it work because clear() is just clearing anything else which may have been in the middle of executing or was going to be executed before the delete call? Meaning, am I clearing something that should have taken place in my other calls to insert, merge, etc, in other functions using the same EntitytManager?


[Updated on: Wed, 12 January 2011 14:13]

Report message to a moderator

Re: Error During Delete: is mapped to a primary key column in the database. Updates are not allowe [message #648371 is a reply to message #648337] Wed, 12 January 2011 16:01 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1035
Registered: July 2009
Senior Member
Hello Joe,

i had writen a response, part of which I put in the bug, but it was lost when posting to the forum. In essence, the test is incorrect because it is not using a valid primary key that will uniquely identify the ALConfigContext entities.

The table itself uses a compound pk, but it seems that the JPA can just use context_id, as it is set using a trigger from a sequence object and so will uniquely identify each row. Any reason for the trigger to set the value, or can you just set your entities to use the sequence object directly? I would recommend you check the demos and examples on setting up an entity with a sequence object, and if you must use the trigger, see post
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg01 319.html

Also, if using a compound pk, JPA requires a primary key class to be set (or an embeddedid). EclipseLink does not force this, but it is required for the app to be portable. Find will still work, but will require a collection containing all primary key values instead of a primary key class.

Best Regards,
Chris
Previous Topic:Deadlock during serialization of entities
Next Topic:Lazy load with detached entities
Goto Forum:
  


Current Time: Fri Oct 31 09:17:47 GMT 2014

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

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