Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException for all non Embedded classes
NullPointerException for all non Embedded classes [message #385185] Tue, 13 January 2009 10:11 Go to next message
Tim Kaltenbrunner is currently offline Tim Kaltenbrunner
Messages: 7
Registered: July 2009
Junior Member
Hi everyone,

I am using the nightly build from 2009-01-09 with @Inheritance(strategy =
InheritanceType.TABLE_PER_CLASS).

I am getting the following Error when I start my application (I am getting
this error for every class which is not embeddable):

java.lang.NullPointerException
at
org.eclipse.persistence.internal.jpa.metadata.accessors.obje cts.MetadataAnnotatedElement.setAnnotatedElement(MetadataAnn otatedElement.java:562)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.obje cts.MetadataAnnotatedElement. <init>(MetadataAnnotatedElement.java:90)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.obje cts.MetadataClass. <init>(MetadataClass.java:32)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.obje cts.MetadataAnnotatedElement.isEmbedded(MetadataAnnotatedEle ment.java:360)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.buildAccessor(ClassAccessor.java:248)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.processAccessorFields(ClassAccessor.java:5 59)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.addAccessors(ClassAccessor.java:226)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.ClassAccessor.processAccessors(ClassAccessor.java:615)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.processAccessors(EntityAccessor.java:611)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor.process(EntityAccessor.java:530)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProces sor.processORMMetadata(MetadataProcessor.java:446)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceU nitProcessor.processORMetadata(PersistenceUnitProcessor.java :303)
at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:837)

I fixed this problem by changing the method hasEmbeddable of class
MetadataProject to contain a check for the class beeng null like:

hasEmbeddable(Class cls)
public boolean hasEmbeddable(Class cls) {
if (cls == null) { //<-- New Line
return false; //<-- New Line
} //<-- New Line
return m_embeddableAccessors.containsKey(cls.getName());
}

and I had to change the method setAnnotatedElement of class
MetadataAnnotatedElement to:

m_annotatedElement = annotatedElement;

// For bug210258, the getAnnotation and isAnnotationPresent method
will
// use the hashmap to determine declared annotation.
m_annotations = new HashMap<String, Annotation>();
if (annotatedElement == null) { //<-- New Line
return; //<-- New Line
} //<-- New Line
for (Annotation annotation :
annotatedElement.getDeclaredAnnotations()) {
String annotationName = annotation.annotationType().getName();
if (annotationName.startsWith(JPA_PERSISTENCE_PACKAGE_PREFIX)
|| annotationName.startsWith(ECLIPSELINK_PERSISTENCE_PACKAGE_PR EFIX)) {
String annotationShortName =
annotation.toString().substring(1, annotation.toString().indexOf("("));
m_annotations.put(annotationShortName, annotation);
}
}
}

Is this something to be changed in the svn? Does anyone have the same
problem?

Cheers Tim
Re: NullPointerException for all non Embedded classes [message #385186 is a reply to message #385185] Tue, 13 January 2009 14:13 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
Please post an example of one of your entities that uses this Inheritance
strategy.

--Gordon
Re: NullPointerException for all non Embedded classes [message #385232 is a reply to message #385186] Tue, 13 January 2009 15:16 Go to previous messageGo to next message
Tim Kaltenbrunner is currently offline Tim Kaltenbrunner
Messages: 7
Registered: July 2009
Junior Member
As an example you can take the following hierarchy:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ADMTop<TADMDataContainer extends IADMDataContainer,
TADMObjectHandleManager extends IADMObjectHandleManager>
implements IADMTop<TADMDataContainer, TADMObjectHandleManager>,
StoreCallback {
private static Logger LOGGER = Logger.getLogger(ADMTop.class);

/**
* A id to compare the object with the version contained in the
database
*/
@Id
@javax.persistence.TableGenerator(
name="JPA_GEN",
table="JDO_SEQUENCE",
pkColumnName = "ID",
valueColumnName = "SEQUENCE_VALUE",
pkColumnValue="0",
allocationSize=200
)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "JPA_GEN")
private int JDOID;

/**
* The objects version field. It is increased by the persistence
implementation
* every time the object is changed
*/
@Column(name = "JDOVERSION")
private Long jdoVersion;
...

@MappedSuperclass
public abstract class ADMObjectImpl<T extends IADMDataContainer, X extends
IADMObjectHandleManager>
extends ADMTop<T, X>
implements IADMObject<T, X>
...

@MappedSuperclass
public abstract class OParameterizedADMObjectImpl<T extends
IADMDataContainer, X extends IADMObjectHandleManager>
extends ADMObjectImpl<T, X> implements IOParameterizedADMObject<T,
X>, IOParameterContext {
...

public abstract class AbstractProjectModel<P extends IRailroadModel>
extends
OParameterizedADMObjectImpl<Project,
ProjectADMObjectHandleManager> implements IProjectModel<P> {
...

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Timetable<TTimetableEntry extends TimetableEntry, TTrain
extends Train>
extends AbstractProjectModel<TTrain> implements
ITimetable<TTimetableEntry, TTrain>, Cloneable, FastReads {
// Backpointer
@OneToOne(targetEntity = Train.class,fetch=FetchType.LAZY)
@JoinColumn(name = "TRAIN_JDOID")
private TTrain train;

@OneToMany(cascade = CascadeType.ALL, targetEntity =
TimetableEntry.class, fetch=FetchType.EAGER)
@IndexColumn(name = "ENTRIES_ORDER", base = 0)
@JoinColumn(name = "TIMETABLE_JDOID")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
private List<TTimetableEntry> entries = new
ArrayList<TTimetableEntry>();
...

I am migrating a Project which uses Hibernate status quo. I am very sorry
that I have only classes within these inheritance hierarchy.

In the posted example the inheritance type should not be a problem because
all the classes Timetable is deriving from are either mapped superclasses
or no entities.

EclipseLink throws the NullPointerException for all classes which aren’t
Embeddable in our Project.

Cheers Tim
Re: NullPointerException for all non Embedded classes [message #385236 is a reply to message #385232] Tue, 13 January 2009 18:32 Go to previous messageGo to next message
Guy Pelletier is currently offline Guy Pelletier
Messages: 19
Registered: July 2009
Junior Member
Tim Kaltenbrunner wrote:

> As an example you can take the following hierarchy:

> @MappedSuperclass
> @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
> public abstract class ADMTop<TADMDataContainer extends IADMDataContainer,
> TADMObjectHandleManager extends IADMObjectHandleManager>
> implements IADMTop<TADMDataContainer, TADMObjectHandleManager>,
> StoreCallback {
> private static Logger LOGGER = Logger.getLogger(ADMTop.class);

> /**
> * A id to compare the object with the version contained in the
> database
> */
> @Id
> @javax.persistence.TableGenerator(
> name="JPA_GEN",
> table="JDO_SEQUENCE",
> pkColumnName = "ID",
> valueColumnName = "SEQUENCE_VALUE",
> pkColumnValue="0",
> allocationSize=200
> )
> @GeneratedValue(strategy = GenerationType.TABLE, generator = "JPA_GEN")
> private int JDOID;

> /**
> * The objects version field. It is increased by the persistence
> implementation
> * every time the object is changed
> */
> @Column(name = "JDOVERSION")
> private Long jdoVersion;
> ...

> @MappedSuperclass
> public abstract class ADMObjectImpl<T extends IADMDataContainer, X extends
> IADMObjectHandleManager>
> extends ADMTop<T, X>
> implements IADMObject<T, X>
> ...

> @MappedSuperclass
> public abstract class OParameterizedADMObjectImpl<T extends
> IADMDataContainer, X extends IADMObjectHandleManager>
> extends ADMObjectImpl<T, X> implements IOParameterizedADMObject<T,
> X>, IOParameterContext {
> ...

> public abstract class AbstractProjectModel<P extends IRailroadModel>
> extends
> OParameterizedADMObjectImpl<Project,
> ProjectADMObjectHandleManager> implements IProjectModel<P> {
> ...

> @Entity
> @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> public class Timetable<TTimetableEntry extends TimetableEntry, TTrain
> extends Train>
> extends AbstractProjectModel<TTrain> implements
> ITimetable<TTimetableEntry, TTrain>, Cloneable, FastReads {
> // Backpointer
> @OneToOne(targetEntity = Train.class,fetch=FetchType.LAZY)
> @JoinColumn(name = "TRAIN_JDOID")
> private TTrain train;

> @OneToMany(cascade = CascadeType.ALL, targetEntity =
> TimetableEntry.class, fetch=FetchType.EAGER)
> @IndexColumn(name = "ENTRIES_ORDER", base = 0)
> @JoinColumn(name = "TIMETABLE_JDOID")
> @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> private List<TTimetableEntry> entries = new
> ArrayList<TTimetableEntry>();
> ...

> I am migrating a Project which uses Hibernate status quo. I am very sorry
> that I have only classes within these inheritance hierarchy.

> In the posted example the inheritance type should not be a problem because
> all the classes Timetable is deriving from are either mapped superclasses
> or no entities.

> EclipseLink throws the NullPointerException for all classes which aren’t
> Embeddable in our Project.

> Cheers Tim

The @Inheritance strategy should not be specified on the MappedSuperclass,
it should be defined on the @Entity itself.
Re: NullPointerException for all non Embedded classes [message #385239 is a reply to message #385236] Wed, 14 January 2009 09:51 Go to previous messageGo to next message
Tim Kaltenbrunner is currently offline Tim Kaltenbrunner
Messages: 7
Registered: July 2009
Junior Member
Thanks,
that explains why the inheritance strategy is still single table per
class hierarchy. By the way, Hibernate JPA handles it different. There the
Inheritance strategy has to be defined on the top class (even if it is a
mapped superclass). I am not sure which implementation interpreted the JPA
spec right. The definition there sounds more like it also can be specified
on a mapped superclass:
2.1.9.2 Mapped Superclasses from JSR 220"A class designated as
MappedSuperclass can be mapped in the same way as an entity except that
the mappings will apply only to its subclasses since no table exists for
the mapped superclass itself.
When applied to the subclasses, the inherited mappings will apply in the
context of the subclass tables."
But your approach is the better suiting one for my project (If it has to
be defined on the top class I have to use the same Inheritance strategy
for all my entity classes because they derive all from ADMTop)

But there is still the problem with the NullPointerException. As I wrote
in my first port I solved it by adding some checks for the collection
being null.

Cheers Tim
Re: NullPointerException for all non Embedded classes [message #385241 is a reply to message #385239] Wed, 14 January 2009 13:13 Go to previous messageGo to next message
Guy Pelletier is currently offline Guy Pelletier
Messages: 19
Registered: July 2009
Junior Member
From what I can tell mapped superclasses are not intended to map
inheritance strategy and the spec definition is perhaps loose. However, if
you look at the xml schema you'll notice that you can not map inheritance
on a mapped superclass there so we followed that definition for
consistency sake between xml and annotations.

As for the NPE, it seems very odd to me. What does your persistence unit
definition in XML look like? Do you map any of the classes in XML?
Re: NullPointerException for all non Embedded classes [message #385248 is a reply to message #385241] Thu, 15 January 2009 09:09 Go to previous messageGo to next message
Tim Kaltenbrunner is currently offline Tim Kaltenbrunner
Messages: 7
Registered: July 2009
Junior Member
I don't use xml files. And my persistence.xml looks the following way:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">

<persistence-unit name="MasterResource">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >

<class>com.qnamic.base.agent.ADMTop</class>
<!-- A LOT OF OTHER CLASSES -->
<class>com.qnamic.railopt.railroad.model.Workshop</class>
<properties>
<property name="eclipselink.jdbc.driver"
value="oracle.jdbc.driver.OracleDriver" />
<property name="eclipselink.jdbc.url"
value="jdbc:oracle:thin:@srv-oracle2:1521:intern02" />
<property name="eclipselink.jdbc.user"
value="MYUSER" />
<property name="eclipselink.jdbc.password"
value="MYPASS" />
<property name="eclipselink.weaving" value="static" />

<!-- property name="eclipselink.cache.type.default" value="Full"/>
<property name="eclipselink.cache.size.default" value="10000"/>
<property name="eclipselink.cache.shared.default" value="true"/>
<property name="eclipselink.flush-clear.cache" value="Merge"/>
<property name="eclipselink.logging.level" value="Fine"/>
<property name="eclipselink.logging.timestamp" value="FALSE"/>
<property name="eclipselink.logging.thread" value="FALSE"/>
<property name="eclipselink.logging.session" value="FALSE"/-->



</properties>
</persistence-unit>
</persistence>

Cheers Tim
Re: NullPointerException for all non Embedded classes [message #385251 is a reply to message #385248] Thu, 15 January 2009 13:01 Go to previous messageGo to next message
Guy Pelletier is currently offline Guy Pelletier
Messages: 19
Registered: July 2009
Junior Member
Looks like the error is coming when trying to resolve the generic type.

Please enter a bug with a paired down test case that reproduces the error
if possible.

Cheers,
Guy
Re: NullPointerException for all non Embedded classes [message #385261 is a reply to message #385251] Fri, 16 January 2009 09:36 Go to previous message
Tim Kaltenbrunner is currently offline Tim Kaltenbrunner
Messages: 7
Registered: July 2009
Junior Member
Ok, I will do that when I find the time to reproduce the bug in a small
example. For now overriding of the two classes I described in the first
post works fine for me.

Cheers Tim
Previous Topic:Unable to insert single entity
Next Topic:ReadAllQuery in 2-tier Swing App
Goto Forum:
  


Current Time: Tue Oct 21 15:17:03 GMT 2014

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

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