Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » (no subject)
(no subject) [message #724422] Mon, 12 September 2011 10:04 Go to next message
Hannes  is currently offline Hannes Friend
Messages: 14
Registered: March 2011
Junior Member
Hello,

I have an @Embeddable class (let's call it EmbeddableParent). EmbeddableParent is subclassed by another class, also annotated with @Embeddable (let's call this class EmbeddableChild). EmbeddableParent also embeds a third class EmbeddableC. To clear things up, a piece of sample code:


@Embeddable
public class EmbeddableC implements Serializable {
private String stringA;
private String stringB;
...
}



@Embeddable
public class EmbeddableParent implements Serializable {
@Embedded
private EmbeddableC embedded;
...
}



@Embeddable
public class EmbeddableChild extends EmbeddableParent implements Serializable {
...
}


I now used the DescriptorCustomizer and InheritancePolicy to make inheritance for Embeddables work, as suggested by en.wikibooks.org/wiki/Java_Persistence/Embeddables#Inheritance (Apparently I cannot post links, unless I have posted more than 5 messages.).

The code I wrote looks like this:


@Customizer(EmbeddableParent.class)
@Embeddable
public class EmbeddableParent implements Serializable, DescriptorCustomizer {
@Embedded
private EmbeddableC embedded;
...
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
descriptor.getInheritancePolicy().setSingleTableStrategy();
DatabaseField indicatorField = new DatabaseField();
indicatorField.setName("QTYPE");
indicatorField.setLength(20);
indicatorField.setType(java.lang.String.class);
descriptor.getInheritancePolicy().setClassIndicatorField(indicatorField);
descriptor.getInheritancePolicy().useClassNameAsIndicator();
}
}



@Embeddable
@Customizer(EmbeddableChild.class)
public class EmbeddableChild extends EmbeddableParent implements Serializable, DescriptorCustomizer {
...
@Override
public void customize(ClassDescriptor descriptor) {
descriptor.getInheritancePolicy().setParentClass(Quantity.class);
}
}


Using this code, generation of tables from entities fails with a NullPointerException:


java.lang.NullPointerException
at org.eclipse.persistence.descriptors.InheritancePolicy.updateTables(InheritancePolicy.java:1847)

1847 Vector<DatabaseTable> parentTables = getParentDescriptor().getTables();

java.lang.NullPointerException
at org.eclipse.persistence.descriptors.InheritancePolicy.postInitialize(InheritancePolicy.java:1122)

1121 ClassDescriptor parent = getParentDescriptor();
1122 if (parent.hasPreDeleteMappings()) {


It seems, parentDescriptor is not set correctly. What am I doing wrong? Did I miss something? Or is it a bug? Any help is appreciated.
(no subject) [message #724604 is a reply to message #724422] Mon, 12 September 2011 16:01 Go to previous message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
> descriptor.getInheritancePolicy().setParentClass(Quantity.class);

Should this be EmbeddableParent not Quantity?
--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Get result count from criteria query
Next Topic:Error Null primary key, but it's not null
Goto Forum:
  


Current Time: Thu Apr 18 09:03:22 GMT 2024

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

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

Back to the top