Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @MappedSuperClass with InheritanceType.JOINED nullPointerException(nullPointer in second subclass if first subclass has InheritanceType.JOINED.)
@MappedSuperClass with InheritanceType.JOINED nullPointerException [message #1669040] Thu, 12 March 2015 18:58 Go to next message
Tercio F. Gaudencio Filho is currently offline Tercio F. Gaudencio FilhoFriend
Messages: 4
Registered: March 2015
Junior Member
My scenario:

@Entity
@MappedSuperclass
public abstract class Base {

    protected int id;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, updatable = false)
    public int getId() {
	return this.id;
    }

    public void setId(final int id) {
	this.id = id;
    }

}

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SubClass1 extends Base {

    private String someField;

    // Getters/Setters ...
}

@Entity
public class SubClass2 extends SubClass1 {

    private String someOtherField;

    // Getters/Setters ...
}


In this case, when I start my application I get this exception:

org.eclipse.persistence.exceptions.IntegrityException: 
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:701) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:637) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:804) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:748) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:253) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:724) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getMetamodel(EntityManagerFactoryDelegate.java:646) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:549) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at my.domain.server.dyn.binder.impl.DynBinderImpl.initialize(DynBinderImpl.java:63) [classes/:?]
	at my.domain.server.controller.impl.ServerControllerImpl.initialize(ServerControllerImpl.java:43) [classes/:?]
	at my.domain.server.tester.DbTester.main(DbTester.java:51) [classes/:?]
2015-03-12T15:40:32,472 ERROR [ org.eclipse.persistence.logging.ejb ] : 134  - 
org.eclipse.persistence.exceptions.IntegrityException: 
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:701) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:637) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:804) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:748) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:253) ~[eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:724) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getMetamodel(EntityManagerFactoryDelegate.java:646) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:549) [eclipselink-2.6.0-RC1.jar:2.6.0.v20150210-f44015d]
	at my.domain.server.dyn.binder.impl.DynBinderImpl.initialize(DynBinderImpl.java:63) [classes/:?]
	at my.domain.server.controller.impl.ServerControllerImpl.initialize(ServerControllerImpl.java:43) [classes/:?]
	at my.domain.server.tester.DbTester.main(DbTester.java:51) [classes/:?]
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.0.v20150210-f44015d): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [myPU] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150210-f44015d): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:859)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:799)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getMetamodel(EntityManagerFactoryDelegate.java:646)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:549)
	at my.domain.server.dyn.binder.impl.DynBinderImpl.initialize(DynBinderImpl.java:63)
	at my.domain.server.controller.impl.ServerControllerImpl.initialize(ServerControllerImpl.java:43)
	at my.domain.server.tester.DbTester.main(DbTester.java:51)
Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.0.v20150210-f44015d): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [myPU] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150210-f44015d): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:239)
	... 8 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150210-f44015d): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:701)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:637)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:804)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:748)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:253)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:724)
	... 6 more


The nullPointer is in the method ClassDescriptor#toggleAdditionalTablePrimaryKeyFields(), line 4326:

...
        while(itTable.hasNext()) {
            Map.Entry<DatabaseTable, Map<DatabaseField, DatabaseField>> entryTable = itTable.next();
            DatabaseTable sourceTable = entryTable.getKey();
            boolean isSourceProcessed = getTables().indexOf(sourceTable) < nProcessedTables;
            int sourceInsertOrderIndex = getMultipleTableInsertOrder().indexOf(sourceTable);
            Map<DatabaseField, DatabaseField> targetTableAdditionalPKFields = entryTable.getValue(); 
            //
            // NullPointer happens here, entryTable is: "DatabaseTable(SubClass2)=null"
            //
            Iterator<Map.Entry<DatabaseField, DatabaseField>> itField = targetTableAdditionalPKFields.entrySet().iterator();
...


What I'm doing wrong?

Regards,
Re: @MappedSuperClass with InheritanceType.JOINED nullPointerException [message #1676681 is a reply to message #1669040] Sun, 15 March 2015 15:38 Go to previous messageGo to next message
Petros Splinakis is currently offline Petros SplinakisFriend
Messages: 12
Registered: September 2014
Junior Member
This is a valid scenario and I have run the following unit test against it with success against 2.6.0:

    @Test
    public void inheritanceTest() {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("PersistenceUnit");
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        EntityTransaction transaction = entityManager.getTransaction();

        SubClass1 subClass1 = new SubClass1();
        subClass1.setSomeField("Some field");
        SubClass2 subClass2 = new SubClass2();
        subClass2.setSomeField("Some field");
        subClass2.setSomeOtherField("Some other field");
        
        int subClass1Id, subClass2Id;
        transaction.begin();
        try {
            entityManager.persist(subClass1);
            entityManager.persist(subClass2);
            transaction.commit();
            Assert.assertTrue("SubClass1 not persisted", (subClass1Id = subClass1.getId()) > 0);
            Assert.assertTrue("SubClass2 not persisted", (subClass2Id = subClass2.getId()) > 0);
        } catch (Exception x) {
            if(transaction.isActive()) {
                transaction.rollback();
            }
            Assert.fail("Failed to persist: " + x.getMessage());
            throw x;
        }
        
        subClass1 = entityManager.find(SubClass1.class, subClass1Id);
        Assert.assertNotNull("Failed to retrieve SubClass1 instance", subClass1);
        subClass2 = entityManager.find(SubClass2.class, subClass2Id);
        Assert.assertNotNull("Failed to retrieve SubClass2 instance", subClass2);
    }


Could you try again with latest EclipseLink version and if your application continues to fail please share your configuration.
Re: @MappedSuperClass with InheritanceType.JOINED nullPointerException [message #1676718 is a reply to message #1676681] Sun, 15 March 2015 15:56 Go to previous message
Tercio F. Gaudencio Filho is currently offline Tercio F. Gaudencio FilhoFriend
Messages: 4
Registered: March 2015
Junior Member
Hi!

Thanks for your reply.

I found out that the problem is with my SessionCustomizer. Probably it is not setting the names correctly in every place.

Thanks again.
Previous Topic:Unabled to set derived IDs
Next Topic:Custom Sequence Generators with NON-JPA API?
Goto Forum:
  


Current Time: Sat Feb 24 14:20:01 GMT 2024

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

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

Back to the top