如何将单个Address类映射到Customer和Employee类?
我有一个基类BaseModel,继承了User类的一些属性。
@MappedSuperclass
public class BaseModel implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "createdOn")
private Date createdOn;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modifyOn")
private Date modifyOn;
// getters and setters
}
//扩展BaseModel以将其属性继承到User
@MappedSuperclass
public class User extends BaseModel {
private static final long serialVersionUID = 1L;
private String firstName;
private String lastName;
private String email;
private String mobileno;
private String username;
private String password;
@OneToMany(mappedBy="user", fetch=FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
private List<Address> address;
//getters and setters
}
//这里扩展User类继承Customer和Employee类中的所有属性。
@Entity
@Table(name="Customer")
public class Customer extends User {
//
}
@Entity
@Table(name="Employee")
public class Employee extends User {
//
}
//这里是例外
org.hibernate.AnnotationException:in.silversun.bean.Address.user上的@OneToOne或@ManyToOne引用了一个未知实体:
我的第一个困惑是,它是多重继承吗?
如果没有,是否可以这样做?如果是,我该如何实现它。非常感谢帮助。谢谢。