我有一个基类,有四个字段a,b,c& d和两个扩展它的子类。
我正在尝试确保SubOne不会保留字段d并且SubTwo不会保留字段c。
下面的xml映射非常有效。
这是否可以使用注释?
(Hibernate v3.2.4,JPA 1.0)
public class Base {
private String a;
private String b;
private String c;
private String d;
}
public class SubOne extends Base {
private int id;
}
public class SubTwo extends Base {
private int id;
private String e;
}
映射:
<class name="SubOne" table="SubOne">
<id name="id" column="Id">
<generator class="identity"/>
</id>
<property name="a" column="a" />
<property name="b" column="b" />
<property name="c" column="c" />
</class>
<class name="SubTwo" table="SubTwo">
<id name="id" column="Id">
<generator class="identity"/>
</id>
<property name="a" column="a" />
<property name="b" column="b" />
<property name="d" column="d" />
<property name="e" column="e" />
</class>
SubOne类:
@Entity
@Table(name="SubOne")
public class SubOne extends Base implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String getA() {
return super.getA();
}
@Override
public String getB() {
return super.getB();
}
@Override
public String getC() {
return super.getC();
}
}