Home » Eclipse Projects » EclipseLink » PrimaryKey-Mapping
PrimaryKey-Mapping [message #376355] |
Wed, 16 July 2008 13:29 |
Georg Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hello,
i run my application with toplink 9.0.4.5 and want to evaluate
eclipselink. For that a run the packageRenamer and make some other changes.
As everything is well compiled, i run my application, but when i commit
changes at the end of one transaction, i got this exception:
Exception Description: The attribute [schwebeKZ] of class
[de.id.aida.grundlagen.model.basis.AidaGFLog] is mapped to a primary key
column in the database. Updates are not allowed.]
Short description, how the application works:
Primary key of nearly all tables: ID_RID, SCHWEBE_KZ
ID_RID is the unique key of one object
SCHWEBE_KZ = 'O' is original, SCHWEBE_KZ = 'S' is lasy
I have a transaction with one and more steps. When i change an object, i
make a clone of the original object and mark it lasy. I also make a new
object, which is marked as lasy. Than i write all objects to the database.
Before:
ID = 1, SCHWEBE = 'O'
After:
ID = 1, SCHWEBE = 'O'
ID = 1, SCHWEBE = 'S'
ID = 2, SCHWEBE = 'S'
Other people could only read the original objects, so they read this
object with (select * from table where id_rid = 1 and schwebe_kz = 'O')
At the end of the transaction, i delete the objects with SCHWEBE_KZ = 'O'
and make an update from SCHWEBE_KZ = 'S' to SCHWEBE_KZ = 'O'.
DELETE FROM TABLE WHERE ID_RID = 1 AND SCHWEBE_KZ = 'O'
UPDATE TABLE SET SCHWEBE_KZ = 'O' WHERE SCHWEBE_KZ = 'S' AND ID IN (1, 2)
With toplink 9.0.4.5 to toplink 10, there is no problem to do so, but
under eclipselink i got this Exception.
What do i have to do, that eclispelink allows me to work like toplink?
I wish, that anyone can help me.
Thank you
Georg
|
|
| |
Re: PrimaryKey-Mapping [message #376375 is a reply to message #376371] |
Fri, 18 July 2008 09:50 |
Georg Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hello Peter,
thank you for your answer.
Here an example for building a descriptor for toplink:
private oracle.toplink.publicinterface.Descriptor
buildHilfeEintragDescriptor() {
oracle.toplink.publicinterface.Descriptor aDescriptor = new
oracle.toplink.publicinterface.Descriptor();
aDescriptor.setAlias("GSHILFE.HilfeEintrag");
aDescriptor.setJavaClass(de.id.aida.backoffice.hilfe.model.p ersistency.HilfeEintragBO.class);
aDescriptor.addTableName("LHTEXT");
aDescriptor.addPrimaryKeyFieldName("LHTEXT.ID_RID");
aDescriptor.addPrimaryKeyFieldName("LHTEXT.SCHWEBE_KZ");
aDescriptor.addMapping(createDirectToFieldMapping(
"id", "getId", "setId", "LHTEXT.ID_RID", false));
"schwebe", "getSchwebe", "setSchwebe", "LHTEXT.SCHWEBE_KZ", false));
aDescriptor.addMapping(createDirectToFieldMapping(
"attributReferenz", "getAttributReferenz", "setAttributReferenz",
"LHTEXT.ATTRREF_CHR", false));
...
AggregateObjectMapping aMapping = new AggregateObjectMapping();
aMapping.setAttributeName("aidaGFLog"); //$NON-NLS-1$
aMapping.setGetMethodName("getAidaGFLog"); //$NON-NLS-1$
aMapping.setSetMethodName("setAidaGFLog"); //$NON-NLS-1$
aMapping.setReferenceClass(AidaGFLog.class);
aMapping.setIsNullAllowed(false);
aMapping.addFieldNameTranslation(pTableName + ".AKTGFID_RID",
"AKTGFID_RID");
aMapping.addFieldNameTranslation(pTableName + ".ANLGFID_RID",
"ANLGFID_RID");
aMapping.addFieldNameTranslation(pTableName + ".HILFGFID_RID",
"HILFGFID_RID");
aMapping.addFieldNameTranslation(pTableName + ".SCHWEBE_KZ",
"SCHWEBE_KZ");
aDescriptor.addMapping(aMapping);
aDescriptor.addDirectQueryKey("aktuelleGFID", pTableName +
".AKTGFID_RID");
aDescriptor.addDirectQueryKey("anlageGFID", pTableName + ".ANLGFID_RID");
aDescriptor.addDirectQueryKey("hilfsGFID", pTableName + ".HILFGFID_RID");
aDescriptor.addDirectQueryKey("schwebeKZ", pTableName + ".SCHWEBE_KZ");
return aDescriptor;
}
For eclipselink, I only change the type of descriptor from Descriptor to
RelationalDescriptor (or should i use the ClassDescriptor?).
We use DB2 as database and set a unique index on the primary key (ID_RID,
SCHWEBE_KZ) and with toplink, i had no problems to delete one row with the
SCHWEBE_KZ = 'O' and make an update from SCHWEBE_KZ = 'O' to 'S'.
Why does eclipselink forbids me to do so? Is it possible to configure
eclipselink to allow me an update on a primary key?
Thanks for your help,
Georg
|
|
| | |
Goto Forum:
Current Time: Fri Apr 26 12:11:02 GMT 2024
Powered by FUDForum. Page generated in 0.02990 seconds
|