Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problems with aggregate collection mappings
Problems with aggregate collection mappings [message #1752728] Thu, 26 January 2017 14:56
Markus Sinsel is currently offline Markus SinselFriend
Messages: 1
Registered: January 2017
Junior Member
Hi,

I am (finally) migrating a project from Toplink to EclipseLink and ran into a problem with some mappings in aggregate collection mappings for 1:n relations.

The mappings are defined in Java. The object structure for one example that causes problems is:
Objects of class Anteil can have 0..n objects of class BankverbAnteil. The according db table has foreign keys references to the PK of the Anteil table.

Mappings are:
// Mapping for BankverbAnteil
// Mappings for the foreign key fields to Anteil
DirectToFieldMapping anteilsNrMapping = new DirectToFieldMapping();
anteilsNrMapping.setAttributeName("anteilsNr");
anteilsNrMapping.setFieldName("BANKVERBANTEIL.ANTEILS_NR");
anteilsNrMapping.readOnly();
descriptor.addMapping(anteilsNrMapping);

DirectToFieldMapping fondsNrMapping = new DirectToFieldMapping();
fondsNrMapping.setAttributeName("fondsNr");
fondsNrMapping.setFieldName("BANKVERBANTEIL.FONDS_NR");
fondsNrMapping.readOnly();
descriptor.addMapping(fondsNrMapping);

// other mappings
// ...

// Amendment method for BankverbAnteil
public static void mappingBankverbindAnteil(ClassDescriptor descriptor) {
		descriptor.setDescriptorType(3);
}


// Mapping for Anteil
// Mappings for the object attributes, nothing related to BankverbAnteil

// Amendment method for Anteil
public static void mappingAnteil(ClassDescriptor descriptor) {
		AggregateCollectionMapping bankverbindAnteilMapping = new AggregateCollectionMapping();
		bankverbindAnteilMapping.setAttributeName("bankverbAnteil");
		bankverbindAnteilMapping.setReferenceClass(BankverbAnteil.class);
		bankverbindAnteilMapping.addTargetForeignKeyFieldName("BANKVERBANTEIL.ANTEILS_NR", "ANTEIL.ANTEILSNR");
		bankverbindAnteilMapping.addTargetForeignKeyFieldName("BANKVERBANTEIL.FONDS_NR", "ANTEIL.FONDS_NR");
		descriptor.addMapping(bankverbindAnteilMapping);
}


With these mappings at some points a NullPointerException like this occurs:
Caused by: Exception [EclipseLink-69] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while extracting a value from the instance variable [aktiv] in the object [com.al_pha.al_pha.server.business.model.anleger.BankverbAnteil].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[aktiv-->BANKVERBANTEIL.AKTIV]
Descriptor: RelationalDescriptor(com.al_pha.al_pha.server.business.model.anleger.BankverbAnteil --> [DatabaseTable(BANKVERBANTEIL)])
	at org.eclipse.persistence.exceptions.DescriptorException.nullPointerWhileGettingValueThruInstanceVariableAccessor(DescriptorException.java:1277)
	at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:88)
	at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:657)
	at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.compareObjects(AbstractDirectMapping.java:409)
	at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.compareForChange(AbstractDirectMapping.java:383)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.createObjectChangeSetThroughComparison(DeferredChangeDetectionPolicy.java:186)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.createObjectChangeSet(DeferredChangeDetectionPolicy.java:146)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.calculateChanges(DeferredChangeDetectionPolicy.java:91)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.calculateChangesForExistingObject(DeferredChangeDetectionPolicy.java:56)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:664)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1516)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitRootUnitOfWork(UnitOfWorkImpl.java:1351)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commit(UnitOfWorkImpl.java:1113)
	at com.al_pha.al_pha.server.business.util.TransactionManager.commitTransaction(TransactionManager.java:117)
	at com.al_pha.al_pha.server.business.util.TransactionManager.commitTransaction(TransactionManager.java:102)
	at com.al_pha.al_pha.server.process.BaseManagementEJB.change(BaseManagementEJB.java:146)
	... 150 more
Caused by: java.lang.NullPointerException
	at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:76)
	... 164 more


A further analysis showed that the mappings (DirectToFieldMappings and OneToOneMappings) of BankverbAnteil attributes exist twice on the heap. One is correct and in one of them the attributeField in the InstanceVariableAttributeAccessor is null.
This problem seems to exist for all mappings of classes that are used in AggregateCollectionMappings (e.g. for all attribute mappings of BankverbAnteil that is used in an AggregateCollectionMapping in Anteil)

With the Toplink version these corrupt Mappings do not exist, a heap comparison showed that the heap of the EclipseLink version contains the same number of Mappings where the attributeField is not null (as in the Toplink version) + those corrupt duplicate mappings.

Any idea what might cause these problems and what I need to change in the mappings to solve this?

Thanks for your help.
Previous Topic:refreshObject after commit causes problem for value change in the next transaction
Next Topic:Constraint violation with @OrderColumn
Goto Forum:
  


Current Time: Thu Dec 14 10:22:50 GMT 2017

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

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