Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException on @VariableOneToOne(Getting NullPointerException on @VariableOneToOne annotation)
NullPointerException on @VariableOneToOne [message #514209] Fri, 12 February 2010 20:25 Go to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: February 2010
Junior Member
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 #515139 is a reply to message #514209] Wed, 17 February 2010 20:56 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Greg,

When defining the @VariableOneToOne annotation, it looks like you need to also set the targetInterface ie;

@VariableOneToOne(
targetInterface=RoleResource.class
discriminatorColumn=@DiscriminatorColumn(
name="resourceClass",
discriminatorType=DiscriminatorType.INTEGER
),
discriminatorClasses={
@DiscriminatorClass(discriminator="3", value=Role.class)
}
)
@JoinColumn(name="resourceId")
private RoleResource resource;


Please feel free to file a bug to get a better error message (or even to have the default be used instead).

Best Regards,
Chris
Re: NullPointerException on @VariableOneToOne [message #515316 is a reply to message #515139] Thu, 18 February 2010 13:33 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: February 2010
Junior Member
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

Re: NullPointerException on @VariableOneToOne [message #515697 is a reply to message #515316] Fri, 19 February 2010 19:47 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Please file a bug for this issue and vote for it. The only workaround I can think of is to map this using EclipseLink native code in a customizer. you could adapt the patch from 261368 (which is closely related) and apply it to the DiscriminatorClassMetadata.process method where it seems to be adding in the string discriminator instead of converting it if neccessary.

Best Regards,
Chris
Re: NullPointerException on @VariableOneToOne [message #515701 is a reply to message #515697] Fri, 19 February 2010 19:57 Go to previous message
No real name is currently offline No real nameFriend
Messages: 3
Registered: February 2010
Junior Member
Chris,

Thanks for the specific suggestions. You have been very helpful. I will create a couple of bugs for these issues. Not sure yet how I will work around the issue. Maybe I just use a string discriminator column.

Greg
Previous Topic:eclipselink dynamic weaving not working from remote computer
Next Topic:Problem with deleting an object with a many-to-many mapping
Goto Forum:
  


Current Time: Thu Apr 18 11:18:08 GMT 2024

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

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

Back to the top