Home » Eclipse Projects » EclipseLink » PrimaryKey-Mapping
PrimaryKey-Mapping [message #376355] |
Wed, 16 July 2008 09:29  |
Eclipse User |
|
|
|
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 05:50   |
Eclipse User |
|
|
|
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
|
|
| |
Re: PrimaryKey-Mapping [message #376378 is a reply to message #376376] |
Mon, 21 July 2008 09:24  |
Eclipse User |
|
|
|
Peter Krogh wrote:
> Looking futher into this, it appears that there is a difference between
> the two streams. The difference was introduced when supporting JPA (JPA
> spec does not allow modifing the PK of an Entity).
> In general I believe that the behaviour of throwing an exception is the
> most desirable.
> However, I understand your usecase, and believe that this support may have
> its place. Can you please enter an EclipseLink enhancement request to add
> a flag to support modification of composite PKs?
> In the mean time the best solution (shor of adding a sequence field to
> your tables...) would likely be to delete the old instance after you
> clone, and insert the new one.
Hello Peter,
thanks for your reply.
I have recompiled eclipselink in a new workspace und make some comments
for the checks of updating primary key columns.
Than i updates the eclipselink.jar and run my application and all is doing
well.
Thank you so far,
Georg
|
|
|
Goto Forum:
Current Time: Wed Jul 23 15:05:49 EDT 2025
Powered by FUDForum. Page generated in 0.03160 seconds
|