[JPA][JBoss7.1]-Java为两个带有JPA注释的表扩展了class 2 Id
我有一个关于设计问题的问题,如下所示:[JPA][JBoss7.1]-Java为两个带有JPA注释的表扩展了class 2 Id,java,jpa,persistence,jboss7.x,Java,Jpa,Persistence,Jboss7.x,我有一个关于设计问题的问题,如下所示: 模板类包含基本信息 扩展模板类的订阅类 两个ID都可以吗 -1模板的id字段 -1订阅的id字段 有两个类,在DB中应该有两个表存储和持久化。 我的设计是:模板是可重用和持久化的,系统可以创建订阅对象副本表单模板类和子订阅类,使用与模板不同的生成Id 因此,我的应用程序的“模板”需要一个Id,“订阅”需要另一个Id 非常感谢你的帮助 编码如下: 模板类 @Entity @Inheritance(strategy=InheritanceType.TABLE_
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name="template")
public class Template implements Serializable{
private static final long serialVersionUID = 12345234567867890L;
@Id @GeneratedValue(generator="hibernate-uuid.hex")
@GenericGenerator(name="hibernate-uuid.hex",strategy = "uuid.hex")
@Column(name="id",length = 40)
protected String id;
@NotNull
@Column(name = "template_attribute",length = 32)
protected String template_atrribute;
...
getter and setter and constructor
使用我的订阅类代码:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@javax.persistence.TableGenerator(name="SID",.................)
@Table(name="user_subscription")
public class UserSubscription extends Template implements Serializable{
@GeneratedValue(strategy=GenerationType.TABLE, generator="SID")
@Column(name="subscriptionId",length = 11)
protected Integer subscriptionId;
@NotNull
@Column(name = "start_date")
protected Date startDate;
//getter and setting and constructor
}