Inheritance eclipselink继承实现
我正试图在我的项目中为继承实现ElcipseLink JPA2.0。 无法使用批注。只有xml映射 这是我的密码。 公共类DefaultEntity{Inheritance eclipselink继承实现,inheritance,jpa,eclipselink,mappedsuperclass,Inheritance,Jpa,Eclipselink,Mappedsuperclass,我正试图在我的项目中为继承实现ElcipseLink JPA2.0。 无法使用批注。只有xml映射 这是我的密码。 公共类DefaultEntity{ } public class SpecialEntity extends DefaultEntity { public String name; public int age; } public class AnotherSplEntity extends DefaultEntity { long ts; String pkey; }
}
public class SpecialEntity extends DefaultEntity {
public String name;
public int age;
}
public class AnotherSplEntity extends DefaultEntity {
long ts;
String pkey;
}
public class MyPersistableEntity {
public DefaultEntity de;
public void setMyPersistableEntity(DefaultEntity de) {
// any subclass can be assigned here.
this.de = de
}
这是我的ORM.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entity-mappings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" version="2.3">
<persistence-unit-metadata>
<exclude-default-mappings />
</persistence-unit-metadata>
<entity class="MyPersistableEntity">
<attributes>
<one-to-one name="de">
<cascade>
<cascade-all />
</cascade>
</one-to-one>
</attributes>
</entity>
<mapped-superclass class="DefaultEntity">
<attributes>
<id name="id" attribute-type="long">
<generated-value strategy="SEQUENCE" />
</id>
</attributes>
</mapped-superclass>
<entity class="SpecialEntity" >
<attributes>
<id name="id" attribute-type="long">
<generated-value strategy="SEQUENCE" />
</id>
<basic name="name" attribute-type="String" />
<basic name="age" attribute-type="int" />
</attributes>
</entity>
</entity-mappings>
我一直在
“使用非实体[class DefaultEntity]作为关系属性[field de]中的目标实体”
如何使EclipseLink识别实际分配的类并使用该映射
有什么想法吗?首先,可以使用EcliseLink吗
谢谢
Gopi如果希望引用具有特殊性,则需要设置目标实体 看,, 或者更好,只需将您的领域类型更改为Speciality
如果可以,那么就不能使用MappedSuperclass,您需要创建DefaultEntity和Entity并映射继承。最终找到了一种方法。 因此,我也用替换并为抽象类创建了一个。不确定这是否是EclipseLink的错误。另一个问题是使用生成值策略“序列”(可能是其他)没有正确生成序列 我的orm如下所示
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entity-mappings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" version="2.3">
<persistence-unit-metadata>
<exclude-default-mappings />
</persistence-unit-metadata>
<entity class="ABC">
<table name="" />
<attributes>
<id .......>
</id>
<basic name="ts" attribute-type="long" />
<one-to-one name="field-referring-to-abstract-class" >
<join-column name="ABSTRACT_ID"/>
<cascade>
<cascade-all />
</cascade>
</one-to-one>
</attributes>
</entity>
<entity class="ABSTRACT-CLASS" >
<table name="ABSTRACT-TABLE"/>
<inheritance strategy="TABLE_PER_CLASS" />
<attributes>
<id name="ABSTRACT_ID" attribute-type="String" >
<column name="ABSTRACT_ID" />
</id>
</attributes>
</entity>
<entity class="SUB-CLASS1-TO-ABSTRACT" access="FIELD">
<table name="SUBCLASS1"/>
<attributes>
<basic name="name" attribute-type="String" />
<basic name="age" attribute-type="int" />
</attributes>
</entity>
<entity class="SUB-CLASS2-TO-ABSTRACT" access="FIELD">
<table name="SUBCLASS2"/>
<attributes>
<basic name="city" attribute-type="String" />
<basic name="zipcode" attribute-type="int" />
</attributes>
</entity>
</entity-mappings>
所以,当我们读取我提供的子类中提供的PK时,这将存储到适当的表中
希望这有帮助
谢谢
Gopi你好,詹姆斯,谢谢你的回复。我不能使用target,因为它可能是任何一个子类。我也不能将字段声明为子类。我正在查看你提到的最后一个选项,你能解释一下这个选项吗?我也不能使用discriminator value/column选项。