Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » PrimaryKey-Mapping
PrimaryKey-Mapping [message #376355] Wed, 16 July 2008 13:29 Go to next message
Georg is currently offline 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 #376371 is a reply to message #376355] Thu, 17 July 2008 17:13 Go to previous messageGo to next message
Peter Krogh is currently offline Peter Krogh
Messages: 8
Registered: July 2009
Junior Member
Are you mapping to exactly the same schema? Is the field a pk on the
database, and is it mapped as a pk in TopLink and EclipseLink?

In otherwords you are getting this error because EclipseLink believes this
field to be a pk, and I believe the reason you are not seeing this in
TopLink, is that TopLink does not think that the field is a pk.

Compare the schemas and the metadata to see if that field is somehow
different between the two versions.

Peter
Re: PrimaryKey-Mapping [message #376375 is a reply to message #376371] Fri, 18 July 2008 09:50 Go to previous messageGo to next message
Georg is currently offline 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
Re: PrimaryKey-Mapping [message #376376 is a reply to message #376375] Fri, 18 July 2008 13:26 Go to previous messageGo to next message
Peter Krogh is currently offline Peter Krogh
Messages: 8
Registered: July 2009
Junior Member
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.
Re: PrimaryKey-Mapping [message #376378 is a reply to message #376376] Mon, 21 July 2008 13:24 Go to previous message
Georg is currently offline Georg
Messages: 3
Registered: July 2009
Junior Member
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
Previous Topic:Dali Java Persistence Tools 2.0 - Feature Highlights
Next Topic:StaticWeavingAntTask didn't weave my classes
Goto Forum:
  


Current Time: Tue Sep 16 07:39:32 GMT 2014

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

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