NullPointerException for all non Embedded classes [message #385185] |
Tue, 13 January 2009 05:11  |
Eclipse User |
|
|
|
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 #385232 is a reply to message #385186] |
Tue, 13 January 2009 10:16   |
Eclipse User |
|
|
|
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 arent
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 13:32   |
Eclipse User |
|
|
|
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 arent
> Embeddable in our Project.
> Cheers Tim
The @Inheritance strategy should not be specified on the MappedSuperclass,
it should be defined on the @Entity itself.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05860 seconds