我正在使用JERSEY在java上构建RESTful服务,并且需要实现仅在另一个实体上存储标识符的实体之间的关系。有没有办法在hibernate中实现它?
我使用过这样的东西但它没有用。
@Entity
@javax.persistence.Table(name = "manager_user")
public class ManagerUser extends User {
@ManyToOne(targetEntity = ShopAdminUser.class)
private Integer shopAdminUserId;
//...
}
@Entity
@javax.persistence.Table(name = "shop_admin_user")
public class ShopAdminUser extends User {
@Lob
private String contactData;
public String getContactData() {
return contactData;
}
public void setContactData(String contactData) {
this.contactData = contactData;
}
}
@Entity
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
public abstract class User {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Integer id;
//...
}
实现这一点对我来说非常舒服。