NullPointerException on @VariableOneToOne [message #514209] |
Fri, 12 February 2010 15:25  |
Eclipse User |
|
|
|
Using EclipseLink 2.0.0 with postgres. Running as a java app inside eclipse.
In a mapped entity I have a reference to interface. I tried mapping using the @VariableOneToOne annotation, but I get an exception when eclipseLink is processing that mapping. I also use the @JoinColumn annotation on this reference.
Here is my original code:
@VariableOneToOne(
discriminatorColumn=@DiscriminatorColumn(
name="resourceClass",
discriminatorType=DiscriminatorType.INTEGER
),
discriminatorClasses={
@DiscriminatorClass(discriminator="3", value=Role.class)
}
)
@JoinColumn(name="resourceId")
private RoleResource resource;
If I remove the @VariableOneToOne annotation, eclipseLink defaults a VariableOneToOne mapping for me. If I use the @VariableOneToOne annotation, even without any arguments, I get this exception:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExc eption
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@11b86e7
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [bardDomain] 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(Per sistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Per sistence.java:54)
at com.netapp.dfm.server.db.DomainEntityTest.buildSessionFactor y(DomainEntityTest.java:44)
at com.netapp.dfm.server.db.DomainEntityTest.getSessionFactory( DomainEntityTest.java:38)
at com.netapp.dfm.server.db.DomainEntityTest.getSession(DomainE ntityTest.java:33)
at com.netapp.dfm.server.db.DomainEntityTest.runTest(DomainEnti tyTest.java:25)
at com.netapp.dfm.server.db.DomainEntityTest.main(DomainEntityT est.java:21)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [bardDomain] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:986)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializ er.callPredeploy(JPAInitializer.java:88)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:124)
... 8 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: Predeployment of PersistenceUnit [bardDomain] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on.predeployFailed(EntityManagerSetupException.java:210)
... 11 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.accessors.mapp ings.ObjectAccessor.getReferenceClass(ObjectAccessor.java:19 1)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.addAccessor(ClassAccessor.java:200)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.addAccessorFields(ClassAccessor.java:349)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.addAccessors(ClassAccessor.java:322)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.preProcess(EntityAccessor.java:657)
at org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.preProcess(EntityAccessor.java:593)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProjec t.processStage1(MetadataProject.java:1296)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProces sor.processORMMetadata(MetadataProcessor.java:460)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceU nitProcessor.processORMetadata(PersistenceUnitProcessor.java :390)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:940)
... 10 more
Thanks for any help.
Greg
|
|
|
|
Re: NullPointerException on @VariableOneToOne [message #515316 is a reply to message #515139] |
Thu, 18 February 2010 08:33   |
Eclipse User |
|
|
|
Thanks Chris. You were correct. Adding the specification of "targetInterface" resolved the NullPointerException. I also agree with your suggestion that the default interface type should be used if not specified, or at least issue a more helpful message.
Now that the NullPointerException is resolved, I hit a second issue. I created the class discriminator column as a numeric type:
resourceClass INTEGER,
and specified as such in the @VariableOneToOne:
discriminatorType=DiscriminatorType.INTEGER
but am syntactically forced to specify the actual discriminator values as Strings, like this:
@DiscriminatorClass(discriminator="3", value=Role.class)
Specifically, when I try this:
@DiscriminatorClass(discriminator=3, value=Role.class)
I get a compile error "Type mismatch: cannot convert from int to String"
and so eclipseLink actually uses a string value in the SQL insert statement, causing an error:
Call: INSERT IGNORE INTO ROLECAPABILITY (ID, ENTITYVERSION, operationId, ownerId, resourceId, resourceClass) VALUES (?, ?, ?, ?, ?, ?)
bind => [8, 1, 6, 7, 7, 3]
Internal Exception: org.postgresql.util.PSQLException: ERROR: column "resourceclass" is of type integer but expression is of type character varying
Is DiscriminatorType.INTEGER not supported by eclipseLink?
Greg
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04164 seconds