JPA: Attr ... mapped to a primary key column in the DB. Update not allowed.

Let me just say that I posted a bug report for this here:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3937
But I'm also posting the info here, so that people who search on this forum may get some help:
TopLink (both Essentials and 11g) has a problem with flushing entities
containing a self-reference relationship. When flushing, the following exception
occurs:
Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.1 (Build b14-fcs
(12/17/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The attribute [id] of class [test.jpa.entities.Person] is
mapped to a primary key column in the database. Updates are not allowed.
No manual updates have been made to ANY primary key.
What I'm doing is:
1. I instantiate a new entity.
2. I start a transaction
3. I persist the new entity.
4. I read an existing entity from the DB.
5. I let the existing entity point to the new entity via the self-reference
relationship.
6. I flush the persistence context.
7. I issue commit(), and the exception occurs. (I have provided the stack traces for various versions of TopLink below.)
This is a clear bug.
Here are some additional observations:
1. Reproduced on the following versions of TopLink:
1.1. Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
1.2. Oracle TopLink Essentials - 2.1 (Build b14-fcs (12/17/2007))
1.3. Oracle TopLink - 11g Technology Preview 3 (11.1.1.0.0) (Build 071214)
2. Reproducible both on Java SE and Java EE. (I tested on Oracle Application Server)
3. Reproducible with and without class weaving
4. Reproducible regardless of whether the JPA annotations are on fields or on
methods
5. Reproducible regardless of whether "cascade={CascadeType.PERSIST}" is used or
not.
6. Reproducible regardless of the fetch type of the self-reference relationship
(EAGER or LAZY).
Also:
1. Without flushing, the bug doesn't occur. That is, if I commit without
flushing, it works.
2. Without setting the self-reference relationship, the bug doesn't occur.
This is an issue that appears when using BOTH self-reference relationship AND
flushing.
Best regards,
Bisser
The message was edited by bisser:
Added info that the exception occurs "when I issue commit()" on step 7.

I'm extremely surprised that you couldn't reproduce the error. It's reproduced each time when I run the Test Scenario that I described above.
You could download a sample Eclipse project that reproduces the error from here: https://glassfish.dev.java.net/issues/show_bug.cgi?id=3937
For the log below I used TopLink, version: Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007)).
Could you, please, tell me what version you use and I will try the Test Case on it.
Here's the FINEST log:
[TopLink Finest]: 2008.01.09 07:35:58.094--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.weaving; value=false
[TopLink Finest]: 2008.01.09 07:35:59.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.orm.throw.exceptions; default value=true
[TopLink Finer]: 2008.01.09 07:35:59.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--Searching for default mapping file in file:/D:/dev/bull/jpa_pk_bug/bin/
[TopLink Config]: 2008.01.09 07:35:59.547--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The alias name for the entity class [class test.jpa.entities.Person] is being defaulted to: Person.
[TopLink Config]: 2008.01.09 07:35:59.594--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The column name for element [private java.lang.Long test.jpa.entities.Person.id] is being defaulted to: ID.
[TopLink Config]: 2008.01.09 07:35:59.609--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The column name for element [private java.lang.String test.jpa.entities.Person.name] is being defaulted to: NAME.
[TopLink Config]: 2008.01.09 07:35:59.641--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The target entity (reference) class for the many to one mapping element [test.jpa.entities.Person test.jpa.entities.Person.mgr] is being defaulted to: class test.jpa.entities.Person.
[TopLink Config]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The primary key column name for the mapping element [test.jpa.entities.Person test.jpa.entities.Person.mgr] is being defaulted to: ID.
[TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end predeploying Persistence Unit Test; state Predeployed; factoryCount 0
[TopLink Finer]: 2008.01.09 07:35:59.703--Thread(Thread[Main Thread,5,main])--cmp_init_transformer_is_null
[TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin predeploying Persistence Unit Test; state Predeployed; factoryCount 0
[TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end predeploying Persistence Unit Test; state Predeployed; factoryCount 1
[TopLink Finest]: 2008.01.09 07:35:59.719--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin deploying Persistence Unit Test; state Predeployed; factoryCount 1
[TopLink Finest]: 2008.01.09 07:35:59.734--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.logging.level; value=FINEST; translated value=FINEST
[TopLink Finest]: 2008.01.09 07:35:59.734--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.logging.level; value=FINEST; translated value=FINEST
[TopLink Finest]: 2008.01.09 07:35:59.750--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.user; value=rms
[TopLink Finest]: 2008.01.09 07:35:59.750--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.password; value=xxxxxx
[TopLink Finest]: 2008.01.09 07:36:00.766--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.target-database; value=Oracle; translated value=oracle.toplink.essentials.platform.database.oracle.OraclePlatform
[TopLink Finest]: 2008.01.09 07:36:00.781--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.driver; value=oracle.jdbc.OracleDriver
[TopLink Finest]: 2008.01.09 07:36:00.781--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.url; value=jdbc:oracle:thin:@//10.20.6.126:1521/region2
[TopLink Info]: 2008.01.09 07:36:00.797--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
[TopLink Config]: 2008.01.09 07:36:00.812--ServerSession(1968077)--Connection(5182312)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:01.797--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:01.797--ServerSession(1968077)--Connection(5744890)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:01.875--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:01.891--ServerSession(1968077)--Connection(5760373)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:01.969--ServerSession(1968077)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:01.969--ServerSession(1968077)--Connection(5497095)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:02.047--ServerSession(1968077)--Connection(5500006)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:02.047--ServerSession(1968077)--Connection(5512041)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:02.125--ServerSession(1968077)--Connection(5514977)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:02.125--ServerSession(1968077)--Connection(5527528)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:02.203--ServerSession(1968077)--Connection(5530440)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Config]: 2008.01.09 07:36:02.203--ServerSession(1968077)--Connection(5542993)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
     platform=>OraclePlatform
     user name=> "rms"
     datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
[TopLink Config]: 2008.01.09 07:36:02.281--ServerSession(1968077)--Connection(5545904)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
     User: RMS
     Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
     Driver: Oracle JDBC driver  Version: 10.2.0.1.0
[TopLink Finest]: 2008.01.09 07:36:02.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing connected, state is Preallocation_NoTransaction_State
[TopLink Info]: 2008.01.09 07:36:02.484--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--file:/D:/dev/bull/jpa_pk_bug/bin/-Test login successful
[TopLink Finest]: 2008.01.09 07:36:02.484--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end deploying Persistence Unit Test; state Deployed; factoryCount 1
[TopLink Finer]: 2008.01.09 07:36:02.516--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--client acquired
[TopLink Finest]: 2008.01.09 07:36:02.531--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query DoesExistQuery()
[TopLink Finest]: 2008.01.09 07:36:02.547--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--PERSIST operation called on: test.jpa.entities.Person@563c8c.
[TopLink Finest]: 2008.01.09 07:36:02.562--ClientSession(5666151)--Thread(Thread[Main Thread,5,main])--Execute query ValueReadQuery()
[TopLink Fine]: 2008.01.09 07:36:02.594--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--SELECT PERSONS_ID_SEQ.NEXTVAL FROM DUAL
[TopLink Finest]: 2008.01.09 07:36:03.297--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing preallocation for PERSONS_ID_SEQ: objects: 1 , first: 5, last: 5
[TopLink Finest]: 2008.01.09 07:36:03.312--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--assign sequence to the object (5 -> test.jpa.entities.Person@563c8c)
[TopLink Finest]: 2008.01.09 07:36:03.328--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query ReadObjectQuery(test.jpa.entities.Person)
[TopLink Fine]: 2008.01.09 07:36:03.438--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--SELECT ID, NAME, MGR_ID FROM Persons WHERE (ID = ?)
     bind => [1]
[TopLink Finest]: 2008.01.09 07:36:03.531--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Register the existing object test.jpa.entities.Person@3a4484
[TopLink Finer]: 2008.01.09 07:36:03.625--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--begin transaction
[TopLink Finest]: 2008.01.09 07:36:03.625--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query UpdateObjectQuery(test.jpa.entities.Person@3a57fa)
[TopLink Finest]: 2008.01.09 07:36:03.641--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query WriteObjectQuery(test.jpa.entities.Person@563c8c)
[TopLink Fine]: 2008.01.09 07:36:03.656--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--INSERT INTO Persons (ID, NAME, MGR_ID) VALUES (?, ?, ?)
     bind => [5, Boss, null]
[TopLink Fine]: 2008.01.09 07:36:03.688--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--UPDATE Persons SET MGR_ID = ? WHERE (ID = ?)
     bind => [5, 1]
[TopLink Finer]: 2008.01.09 07:36:03.703--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--begin unit of work commit
[TopLink Finest]: 2008.01.09 07:36:03.703--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query UpdateObjectQuery(test.jpa.entities.Person@563c8c)
[TopLink Warning]: 2008.01.09 07:36:03.812--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Local Exception Stack:
Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
     at oracle.toplink.essentials.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2222)
     at oracle.toplink.essentials.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:750)
     at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.buildRowForUpdateWithChangeSet(ObjectBuilder.java:948)
     at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1263)
     at oracle.toplink.essentials.queryframework.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:91)
     at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:390)
     at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:109)
     at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
     at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:555)
     at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:138)
     at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:110)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
     at oracle.toplink.essentials.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:309)
     at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:195)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2657)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1044)
     at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:403)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1126)
     at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:107)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:856)
     at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:102)
     at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:60)
     at test.jpa.TestPkBug.runTest(TestPkBug.java:53)
     at test.jpa.TestPkBug.main(TestPkBug.java:95)
[TopLink Finer]: 2008.01.09 07:36:03.828--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--rollback transaction
[TopLink Finer]: 2008.01.09 07:36:03.844--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--release unit of work
[TopLink Finer]: 2008.01.09 07:36:03.844--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--initialize identitymaps
[TopLink Finer]: 2008.01.09 07:36:03.844--ClientSession(5666151)--Thread(Thread[Main Thread,5,main])--client released
[TopLink Finest]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin undeploying Persistence Unit Test; state Deployed; factoryCount 1
[TopLink Finest]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing disconnected
[TopLink Config]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Finer]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--initialize identitymaps
[TopLink Info]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--file:/D:/dev/bull/jpa_pk_bug/bin/-Test logout successful
[TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5182312)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5500006)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5514977)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5530440)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5545904)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Config]: 2008.01.09 07:36:03.891--ServerSession(1968077)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--disconnect
[TopLink Finest]: 2008.01.09 07:36:03.891--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end undeploying Persistence Unit Test; state Undeployed; factoryCount 0
Exception in thread "Main Thread" javax.persistence.RollbackException: Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
     at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:120)
     at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:60)
     at test.jpa.TestPkBug.runTest(TestPkBug.java:53)
     at test.jpa.TestPkBug.main(TestPkBug.java:95)
Caused by: Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
     at oracle.toplink.essentials.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2222)
     at oracle.toplink.essentials.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:750)
     at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.buildRowForUpdateWithChangeSet(ObjectBuilder.java:948)
     at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1263)
     at oracle.toplink.essentials.queryframework.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:91)
     at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:390)
     at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:109)
     at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
     at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:555)
     at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:138)
     at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:110)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
     at oracle.toplink.essentials.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:309)
     at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:195)
     at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2657)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1044)
     at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:403)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1126)
     at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:107)
     at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:856)
     at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:102)
     ... 3 moreEDIT: Are you using the EXACT Test Case as I have described it in the previous posts? It's important that you commit(), and not rollback(), the transaction after the flush.
EDIT: Updated the log because I found out that I had made a small change to the original Test Case while I was trying to find a workaround. The current log is produced by the EXACT Test Case I described in my previous posts.
Message was edited by:
bisser

Similar Messages

  • Primary key column as the key of the cache

    Hi All,
    I am implementing a cache backed by HibernateCacheStore for a table. Cache contains key as the primary key of the table and value as the entire row in object format. the primary key is generated by hibernate.
    when i am inserting new rows through coherence (i.e cahce.put) what persistence strategy should is use to set the cache entries.
    I cannot use cache.put (key, value) because key is the primary key of the table which is not generated yet.
    and if i use the session.save(value) the persisted value is not in the cache.
    is there any mechanism to map the cache key as the primary key column of the table.
    Regards
    S

    Hi -
    Using Hibernate as a CacheStore for Coherence, the key of the cache entry is also the key of the entity
    being stored via Hibernate. For this reason keys for new cache entries must be generated ahead of time.
    A UUID can be used. The commons component of the Incubator project has a key generation utility that
    might be worth looking at.
    /Mark

  • Knowing the primary key columns of the given table

    Hi,
    How can I get the primary key columns of the given table?
    Regards,
    Sachin R.K.

    You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
    And then see which columns are in for the constriant_name
    in all_cons_columns/user_cons_columns view.
    Below is the example
    select acc.column_name from
    all_cons_columns acc, all_constraints ac
    where acc.constraint_name = ac.constraint_name
    and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
    and ac.constraint_type = 'P'
    Hope this helps
    Srinivasa Medam

  • FillSchema picks too many primary key columns

    I don't know whether this is an ODP.NET error or a Microsoft error.
    Oracle9i Release 9.2.0.1.0
    ODP.NET 9.2.0.4
    .NET Framework 1.1
    Create a table with one primary key column and one unique column and name the primary key column like the unique column with the suffix "_ID":
    CREATE TABLE t_bib_uebertrag_kap(
    &nbsp kapazitaet_id NUMBER(8) NOT NULL
    &nbsp&nbsp CONSTRAINT pk_kapa primary key,
    &nbsp kapazitaet VARCHAR2(15) NOT NULL
    &nbsp&nbsp CONSTRAINT a_un_kapa unique,
    &nbsp geschwindigkeit NUMBER(12) NOT NULL,
    &nbsp bemerkung VARCHAR2(255)
    After calling FillSchema on this table the PrimaryKey property of the DataTable contains 2 columns: KAPAZITAET_ID and KAPAZITAET.
    The same happens with other tables and similar column names
    R. Lüthke

    Tony, I'm gonna find time to try this because I was thinking it probably would be a double check.
    BUT... Oracle is written in C, and I imagine the extra check as a simple if comparison for the new value versus a constant NULL value. Kind of like checking for end of string. It's already doing things like checking datatypes and that as it inserts data, and I don't think this additional check (if it even exists) would add any significant overhead.
    But unless I find a much larger performance hit than I expect, I'm gonna stick with creating the NOT NULL's explicitly. Good data modelling trumps small performance tricks for me.
    My main worry is if/when somebody removes the primary key constraint (such as the example above where they might do a CREATE TABLE x AS SELECT * FROM y). Or if the data model gets updated to where the primary key becomes just a unique key, then the NOT NULL goes away when it shouldn't. I don't like basic table and column properties changing.
    Okay.. test done. Ran about 31,000 records from dba_tables through an insert into two tables, both with primary keys and one with explicit NOT NULLs. No measurable difference in stats detected.
    With NOT NULL and PRIMARY KEY:
    call count cpu elapsed disk query current rows
    Parse 1 0.35 0.35 0 0 0 0
    Execute 1 1.88 1.83 0 24792 35887 30954
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 2.24 2.18 0 24792 35887 30954
    Now with only PRIMARY KEY.
    call count cpu elapsed disk query current rows
    Parse 1 0.37 0.36 0 0 0 0
    Execute 1 1.87 1.83 0 24792 35887 30954
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 2.24 2.19 0 24792 35887 30954

  • Add primary key column to fact tables?

    Our datawarehouse folks asked me if they could add a primary key column in the BPC fact tables.  Anyone know if this is possible??
    Edited by: Shawn Freundschuh on Apr 3, 2009 12:27 PM

    Well.. based on my expeirence, it is not possible.
    When you run admin console, sometimes it will return error message.
    I tried it before but you can try it again. Maybe developer changed its behavior.
    Thanks.

  • Selection criteria based on non-primary key columns in Custom-SQL

    Hi all,
    Could anybody please tell me how to perform a search using non-primary key columns, The query is written in Workbench under Custom Sql --> Read Object. The Query goes something like this
    select * from Employee where firstName like #name
    where firstName is a Non-primary key column.
    The Java Code goes like this
    Employee empm = new Employee();
    empm.setFirstName("John");
    Employee employees = (Employee) session.readObject(empm);
    This does not fetch me any values . I dont want the queries to be written in any java class. Is there Any other way to do it ??

    Hi all,
    Could anybody please tell me how to perform a
    search using non-primary key columns, The query is
    written in Workbench under Custom Sql --> Read
    Object. The Query goes something like this
    select * from Employee where firstName like #name
    where firstName is a Non-primary key column.
    The Java Code goes like this
    Employee empm = new Employee();
    empm.setFirstName("John");
    Employee employees = (Employee)
    session.readObject(empm);
    This does not fetch me any values . I dont want the
    queries to be written in any java class. Is there Any
    other way to do it ??I dont think you have set it up the right way to do what you want to do. You need to click on "Queries" on the Employee Descriptor and then Named Queries and then give a name for a named query and then choose ReadObjectQuery under type and then choose SQL under Format. Enter the custom SQL and then export the project xml file.
    Then in your application logic you have to call this named query the usual way.
    Employee employee = (Employee)session.executeQuery("findEmployeeByName,Employee.class,args);
    where args is a vector containing the name of the Employee.

  • No Primary Key Column set. error

    Hi all,
    Firstly, thank you to DWFAQ for advice a tutorials.
    Secondly, I have built a contact form using the update record
    form wizard in ADDT -
    http://dwfaq.info/home.php?id=4
    I have hit a problem, when running the form I get the
    following error:
    Error:
    Internal error.
    Developer Details:
    tNG_update.prepareSQL:
    No Primary Key Column was set. (UPD_NO_PK_SET)
    tNG Execution Trace - VIEW
    * tNG_update.executeTransaction
    o STARTER.Trigger_Default_Starter
    o tNG_update.doTransaction
    + BEFORE.Trigger_Default_saveData
    # tNG_update.saveData
    + BEFORE.Trigger_Default_FormValidation
    + tNG_update.prepareSQL*
    o tNG_update.getRecordset
    o tNG_update.getFakeRsArr
    o tNG_update.getLocalRecordset
    o tNG_update.getFakeRecordset
    Could somebody please help - I'm so close it hurts ;-)
    Thank you
    NJ

    Heya,
    Looks like your DB is all setup correctly it must be the
    primary key in the transaction of the script.
    Make sure id is set as the primary key in your Update Record
    Form Wizard. You php code should look something like this:
    // Add columns
    $upd_contact->setTable("cvform");
    $upd_contact->addColumn("firstname", "STRING_TYPE",
    "POST", "firstname");
    $upd_contact->addColumn("lastname", "STRING_TYPE", "POST",
    "lastname");
    $upd_contact->addColumn("email", "STRING_TYPE", "POST",
    "email");
    $upd_contact->addColumn("message", "STRING_TYPE", "POST",
    "message");
    $upd_contact->addColumn("attachment", "FILE_TYPE",
    "FILES", "attachment");
    $upd_contact->addColumn("phonenumber", "STRING_TYPE",
    "POST", "phonenumber");
    $upd_contact->setPrimaryKey("id", "NUMERIC_TYPE", "VALUE",
    "id");
    // Execute all the registered transactions
    $tNGs->executeTransactions();
    You may have to post your script to see what the problem is.
    Most likely something not followed correctly in the tutorial. If
    you are able to post your php script as a text file then link to
    the file here with .txt extension I can take a look at it and see
    where the problem is. Make sure to remove any info that may
    compromise your database when providing your php script or contact
    me through my website and I can help you out off the forum.
    Hope that helps!

  • How to know primary key column name form a table name in sql query

    Suppose I only know the table name. How to get its primary key column name from the table name?
    Thanks

    Views don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
    You can select the text of the view in question from user_views.

  • The column in the table do not match an existing primary key

    I've got two tables tbl_Workshop and tbl_Material
    tbl_Workshop has columns workshopID, workshopTitle, materialID
    tbl_Material has materialID, name, workshopTitle
    when I'm trying to create a relationship between the workshopTitle of tbl1 and tbl2, it gives me an error that says the column in the table do not match an existing primary key.
    What could be the reason for this error and how to overcome it.
    ps. The datatypes and names of both the table's column match.

    Have you created primary key on workshopTitle column in tbl_Workshop
    You can add foreign key relationship from tbl_Material.workshopTitle
    to tbl_Workshop.workshopTitle
     only if latter is a primary key of the table.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Primary key column auto increment

    Hello,
    In my Azure SQL Database I noticed that weird thing is happening. I have table with primary key column with auto increment, and all works fine, on new insert that value automatically increment, but every now and then, that value, for no reason, increments
    for 1000.
    For instance i have in DB values in this order: 1, 2, 3, 4, 1001, 1002, 1003, 2004,  2005, 3001, 3002...
    Why is this happening? 

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • IDOC to MSsql,  error in mapping(Violation of PRIMARY KEY constraint)

    Hi All,
    I'm working with MATMAS IDOC  to MSSql. My SQL structure is of 8 tables(multiple statements) with primary key. In mapping i have used UPDATE_INSERT in action field for all the tables but still im getting "Violation of PRIMARY KEY constraint" for the last table structure. first 7 tables are single occurances but the 8th structure data is coming multple times from IDOC(E1MARMM).
    my 8th table structure is :
    STATEMENT8                                IDOC(MAPPED)
    TABLE8
    ACTION                                      UPDATE_INSERT
    TABLE                                           TABLENAME
    ACCESS     0 to Unbounded            MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Numerator_For_Conversion_To_BaseUOM
    Display_UOM
    Denominator_for_conversion_To_baseUOM
    KEY           0 to Unbounded                 MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Display_UOM
    in test tab its fine and fetching number of times according to MARMM segments  but in END to END testing its triggering an error stating that
    ""Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'MM_EAN' (structure 'STATEMENT8'): com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_MM_EAN'. Cannot insert duplicate key in object 'dbo.MM_EAN'.  ""
    Plz help me regarding this..

    Hi team,
    How resolve the below error 
    Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?
    Thanks,
    Ram
    RAM
    There can be two reasons
    1. The insert script used is having multiple instances of the records with Key as 12610 returned from the source query. If this is the issue add a logic to include only the unique set of id values for records by avoiding duplicates. There are several approaches
    for this like using ROW_NUMBER with PARTITION BY, using a join with derived table etc
    2. The record with Key 12610 already exist in your destination table and your script is again trying to insert another instances of record with same key. This can be avoided by adding a NOT EXISTS condition with a subquery which will check and return only
    those records which doesnt already exist in the source
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Switch the sequence of Primary Key Columns

    Hi MaxDB experts,
    As part of our product upgrade we've made a schema change to 10 of our database tables. Typically these tables contain about 5 million rows in them. The change involves switching the order of columns in the primary key (original order SampleTime, Id; new order would be Id, SampleTime). What's the quickest way to achieve this?
    So far I've tried the following approaches without much luck:
    1. Use the "alter table alter primary key (new seuqence of columns)". Takes an average of 1 hour per table.
    2. Copy original table content into another table with "insert into newTable (select * from existingTable)" command. Takes the same amount of time as #1
    3. Tried using "Export Table" option presented by the "loadercli". Unfortunately, exported data can not be imported to a table with a different schema (in our case changed primary key column sequence).
    What else can we try? Any advise / direction would be greatly appreciated. Thanks for your time.
    Sincerely,
    Sameer Apte

    Hi there,
    ok, I assume that you figured out that you like to have data entries belonging to a specific ID stored rather nearby than scattered around in the table by TIMESTAMP or that you have more queries that specify the ID but not the TIMESTAMP.
    Both would be good reasons to perform such a change.
    Concerning the speed: basically things won't get any faster than ALTER TABLE or INSERT (SELECT * FROM)...
    The ALTER TABLE approach would have the advantage to be transactional atomic and simple to use.
    The INSERT approach would enable the use of the PREFETCHING feature for the read-I/O on the source table.
    So if you're just focussing on speed, then I'd recommend to:
    setup a data cache that can hold both source and target tables im memory
    enable prefetching by setting the parameter READAHEAD_TABLE_THRESHOLD to say 128 (be aware that you've to use MaxDB 7.6.05 or higher, but not 7.7.x  for that!)
    After you've copied each table, make sure to create the secondary indexes one by one since otherwise the internal parallelism won't be used.
    regards,
    Lars
    p.s.
    it is possible to export/import into different schemas - it's even supported via DB Studio.
    Anyhow, it wouldn't make anything quicker for this case.

  • Partition key on non primary key column

    I have scenario where the table has defined non primary key column as "partition key".
    I was wondering how it will affect the purge/archive process if the index and table are using different column (they are not aligned)?
    What should be the solution to this scenario?
    Can I use the non primary key column as partition key? Is this affect purging/archiving or switching -IN or OUT partitions?
    Here is the article which Im following but didn't get the precise answer:
    "When the indexes and the table use the same partitioning function and columns in the same order, the table and index
    are aligned." 
    https://msdn.microsoft.com/en-US/library/ms345146%28v=SQL.90%29.aspx?f=255&MSPPError=-2147217396#sql2k5parti_topic9
    Look at "Index
    Partitioning" and "Defining
    the Partitioning Key" section.
    ZK

    If it non aligned, you cannot do switching in or out.  to switch, you should have aligned partitons.
    Hope it Helps!!

  • How can I modify a column to a primary key column

    Hi,
    I've created a table with no primary key. How I can set the primary key column now? The datatype of the "primary key" column is Raw(35).
    Thanks,
    Mike

    Mike,
    Issue the following command:
    ALTER TABLE table_name
    ADD CONSTRAINT constraint_name PRIMARY KEY(column_name);
    NOTE: If you want to place the primary key data in a separate tablespace, then you can add the key word USING INDEX TABLESPACE after the column_name.
    Regards,
    John

  • Ability to auto create a primary key column while creating an entity ?

    Product : oracle data modeler ( 3.0.0.665 32 bit version ) on windows XP Professional , : Target DB Oracle 11GR2
    I am new to Mozilla Rhino. Is it feasible to have a mechanism where in the primary key column name would be auto generated when the entity ( name ) is just created for the first time, and it has no columns defined yet . For e.g. one could create an entity named vendor , and after the table name is typed in, a column vendor identifier,of type numeric , is to be auto created. This mechanism should work even if the entity name changes, and the primary key is in format {tablename}_id , but it should not , if the primary key was manually set in later and is not in the expected format.

    I created this script (1) for adding an ID column (using a specific domain) to all supertype entities that do not already have an ID attribute, and a script (2) for adding primary key constraints to all ID attributes.
    - Marc de Oliveira
    Script 1:
    entities = model.getEntitySet().toArray();
    domain = model.getDesign().getDomainSet().getByName('Integer DIS Domain');
    for (var e = 0; e<entities.length;e++)
    entity = entities[e];
    if (entity.getHierarchicalParent()==null)
    attributes = entity.getAttributes().toArray(); // find existing attributes
    IDattribute = null;
    for (var a = 0; a<attributes.length; a++) // look for an ID attribute
    if (attributes[a].getName()=="ID") { IDattribute = attributes[a]; }
    if (IDattribute==null) // if an ID attribute was not found...
    IDattribute = entity.createAttribute(); // create a new ID attribute
    IDattribute.setName("ID");
    IDattribute.setDomain(domain);
    entity.moveToIndex(IDattribute,0); // move ID attribute to top
    Script 2:
    entities = model.getEntitySet().toArray();
    for (var e = 0; e<entities.length;e++)
    entity = entities[e];
    attributes = entity.getAttributes().toArray(); // find existing attributes
    IDattribute = null;
    for (var a = 0; a<attributes.length; a++) // look for an ID attribute
    if (attributes[a].getName()=="ID") { IDattribute = attributes[a];}
    if (IDattribute!=null) // if an ID attribute was found...
    key = entity.createCandidateKey(); // Create a key
    key.add(IDattribute); // Add the ID attribute to the key
    key.setPK(true); // Define the key as a primary key
    PKName = entity.getName().replace(" ","_")+"_PK";
    key.setName(PKName); // Define the key as a primary key
    entity.setPK(key); // workaround for bug...
    }

Maybe you are looking for

  • REPORT TO CHECK DIFFERENCE G.R DATE AND U.D DATE FOR A INSP LOT

    Hi I want to track how many dates it has been taken to clear a insp lot for a G.R. So I am looking for a report which shows these days or a report which have G.R date and U.D for inspection lot. Please guide if there are any reports for this. Thanks

  • I can't see my full wish list

    I can only see the top 30 or so songs on my wish list, but i have way more than that

  • Impact of enabling Conversion in transfer rule

    Hi Experts, From last two days I am facing an issue while loading the data in a object which has conversion exit as ALPHA. When any numeric value is coming it ig giving an error message, i searched SDN and found out that in tranfer rule if I enable c

  • How do I get the watch to stay awake longer?

    I noticed that when I am using the watch, it only stays awake for a matter of seconds before going dark.  For example, I was using the Stop Watch app and while trying to time something, the watch went dark after a few seconds.  This caused me to have

  • Have imported video into audition but how do I get the audio to snap after editing?

    Just to explain, I have imported a timeline from Premiere into Audition CC. I have one full piece of video and one piece of audio but need to clean up the audio. What I'm trying to do is edit the audio and have it snap to the piece of audio to the le