Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Inheritance with Embeddables on NoSQL/MongoDB using eclipselink 2.4.1

Hello,

I try to use inheritance with Embeddables using DescriptorCustomizer (as described here -> http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Embeddable) but i get this nasty Exception:

Exception Description: Normal descriptors do not support non-relational extensions.
Descriptor: RelationalDescriptor(test.model.ChildA --> [])

What I try is to store a inherited embeddable ChildA object inside the "Document" entity.
Can anyone explain me why it doesn't work?

This is my source code:
@Test
public void testInheritance() {
ChildA childA = new ChildA();
childA.setBaseAttribute("some base attribute text");
childA.setChildAProperty("child a property text");

Document doc = new Document();
doc.setSomeChild(childA);

EntityManagerFactory factory = Persistence.createEntityManagerFactory("mongo");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(doc);
em.getTransaction().commit();
em.close();
}


@Entity
@NoSql(dataType = "MyDocs", dataFormat = DataFormatType.MAPPED)
public class Document {
@Id
@GeneratedValue
@Field(name = "_id")
private String id;

@Embedded
private BaseChild someChild;
...
}

@Embeddable
@NoSql(dataFormat = DataFormatType.MAPPED)
@Customizer(BaseCustomizer.class)
public class BaseChild {

@Basic
@Field(name="baseAttribute")
private String baseAttribute;
...
}

@Embeddable
@NoSql(dataFormat = DataFormatType.MAPPED)
@Customizer(ChildCustomizer.class)
public class ChildA extends BaseChild {

@Basic
@Field(name = "childAProperty")
private String childAProperty;
...
}

public class BaseCustomizer implements DescriptorCustomizer {

@Override
public void customize(ClassDescriptor descriptor) throws Exception {
descriptor.getInheritancePolicy().setClassIndicatorFieldName("type");
descriptor.getInheritancePolicy().addClassIndicator(ChildA.class, "ChildA");
descriptor.getInheritancePolicy().addClassIndicator(ChildB.class, "ChildB");
}
}

public class ChildCustomizer implements DescriptorCustomizer {

@Override
public void customize(ClassDescriptor descriptor) throws Exception {
descriptor.getInheritancePolicy().setParentClass(BaseChild.class);
}

}




Back to the top