Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA 2.0 Problem: NPE

Hello,

The JPA spec requires a primary key class defined if you have a composite primary key.  You need to define a key class on the root entity if you want it to have more than one field annotated with @Id.

Best Regards,
Chris


----- Original Message -----
From: sascha.broich@xxxxxx
To: eclipselink-users@xxxxxxxxxxx
Sent: Tuesday, December 15, 2009 6:18:30 AM GMT -05:00 US/Canada Eastern
Subject: [eclipselink-users] JPA 2.0 Problem: NPE

Hi,

I ran into an error while trying to use eclipselink 2.0.0 with javax.persistence 2.0.0.

The setting is:

I have an abstract class A with 3 primary key columns, annotated with @Id.
>From this I have derived classes B and C, with Inheritance strategy table_per_class.

Now when I try to initialize the EntityManagerFactory I get an NullpointerException at 

MetadataDescriptor.setPKClass(MetadataClass) line: 1516

        policy.setPrimaryKeyClassName(pkClass.getName());


This is because the pkClass parameter is null.


The problem, I think, is as follows. The call comes from 

InheritanceMetadata.process(MetadataDescriptor) line: 152	

	// If the root descriptor has an id class, we need to set the same 
      // id class on our descriptor.
      if (descriptor.getInheritanceRootDescriptor().hasCompositePrimaryKey()) {
          descriptor.setPKClass(descriptor.getInheritanceRootDescriptor().getPKClass());
      }


MetadataDescriptor.hasCompositePrimaryKey() method:

	return getPrimaryKeyFields().size() > 1 || getPKClass() != null


So my class A has no PKClass but 3 primary key fields.
I assume that either the  MetadataDescriptor.setPKClass has to be made NPE-safe or 
the if-statement in InheritanceMetadata.process has to be changed to "hasPKClass()".


Regards,
Sascha Broich

-- 
Sascha Broich
Entwicklung

TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Tel: +49 39203 8 2524 
E-Mail: Sascha.Broich@xxxxxx

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top