Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException on combining inheritance strategies (table per class + joined)
icon4.gif  NullPointerException on combining inheritance strategies (table per class + joined) [message #537517] Wed, 02 June 2010 13:37 Go to next message
Ernesto Trajano de Lima is currently offline Ernesto Trajano de Lima
Messages: 4
Registered: July 2009
Junior Member
Hi,

I'm trying to combine table per concrete class and joined subclass strategies (classes are attached to this message - imports were omitted). However, all I get is a NPE (stack trace below). I'm just creating the entity manager (test also attached)

Are there any limitations to the use of these strategies together or should I file a bug report?

Thanks!

------ Classes
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name="MAIN_ENTITY_TAB")
public class MainEntity {

@Id
private Long id;

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

public Long getId() {
return id;
}
}

---
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "DICRIMINATOR")
@DiscriminatorValue("0")
@Table(name = "MAIN_ENTITY_TAB")
@SecondaryTable(name="SECONDARY_TAB")
public class SubEntity extends MainEntity {

@Column(name = "DICRIMINATOR", table="SECONDARY_TAB", length = 1, nullable = false)
private Integer discriminator;

public void setDiscriminator(Integer discriminator) {
this.discriminator = discriminator;
}

public Integer getDiscriminator() {
return discriminator;
}


}

------ Test used
@Test
public void testEntityManagerCreation() {
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("jpa-spec-testing");
EntityManager entityManager = emFactory.createEntityManager();
}


----------------- Stack trace
Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExc eption
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@198dfaf
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [jpa-spec-testing] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingExc eption.exceptionSearchingForPersistenceResources(Persistence UnitLoadingException.java:126)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:133)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:65)
at javax.persistence.Persistence.createEntityManagerFactory(Unk nown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unk nown Source)
at entities.InheritanceTest.testEntityManagerCreation(Inheritan ceTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:197)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [jpa-spec-testing] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:991)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializ er.callPredeploy(JPAInitializer.java:88)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:124)
... 28 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [jpa-spec-testing] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on.predeployFailed(EntityManagerSetupException.java:210)
... 31 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.inheritance.In heritanceMetadata.process(InheritanceMetadata.java:102)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.processInheritance(EntityAccessor.java:10 07)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.processTableAndInheritance(EntityAccessor .java:1289)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.process(EntityAccessor.java:690)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProjec t.processStage2(MetadataProject.java:1333)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProces sor.processORMMetadata(MetadataProcessor.java:461)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceU nitProcessor.processORMetadata(PersistenceUnitProcessor.java :390)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:945)
... 30 more
Re: NullPointerException on combining inheritance strategies (table per class + joined) [message #537522 is a reply to message #537517] Wed, 02 June 2010 14:21 Go to previous messageGo to next message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de Andrade
Messages: 44
Registered: July 2009
Member
Hi, Ernesto!
Just one question: how can you combine these strategies?

Table per Class Hierarchy Strategy ==>In this strategy, all the classes in a hierarchy are mapped to a single table.

Joined Subclass Strategy ==>In the joined subclass strategy, the root of the class hierarchy is represented by a single table. Each subclass is represented by a separate table that contains those fields that are specific to the subclass (not inherited from its superclass), as well as the column(s) that represent its primary key. The primary key column(s) of the subclass table serves as a foreign key to the primary key of the superclass table.

Hope this help,

Giberto

[Updated on: Wed, 02 June 2010 14:24]

Report message to a moderator

Re: NullPointerException on combining inheritance strategies (table per class + joined) [message #537527 is a reply to message #537522] Wed, 02 June 2010 14:51 Go to previous messageGo to next message
Ernesto Trajano de Lima is currently offline Ernesto Trajano de Lima
Messages: 4
Registered: July 2009
Junior Member
Hi Gilberto,

The "InheritanceType.TABLE_PER_CLASS" strategy doesn't map classes to a single table. That happens when you choose the "InheritanceType.SINGLE_TABLE" strategy.

See:
< http://java.sun.com/javaee/5/docs/api/javax/persistence/Inhe ritanceType.html>

Thanks!
Ernesto.
Re: NullPointerException on combining inheritance strategies (table per class + joined) [message #537730 is a reply to message #537517] Thu, 03 June 2010 09:38 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA does not allow you to have more than one type of inheritance in a hierarchy. You may try instead using a @MappedSuperClass instead of TABLE_PER_CLASS in the root.

EclipseLink should not be throwing a null-pointer though, so please log a bug for that. Also being able to change the inheritance type is a subclass would be desirable, so please log an enhancement for that.

EclipseLink's native API gives you much more freedom in inheritance than JPA, so you may try defining or customizing your descriptors through the ClassDescriptor API.


James : Wiki : Book : Blog : Twitter
Previous Topic:Delete from collection
Next Topic:Map to a column that may not exist
Goto Forum:
  


Current Time: Wed Jul 23 20:20:47 EDT 2014

Powered by FUDForum. Page generated in 0.01783 seconds