【发布时间】:2012-12-17 21:54:03
【问题描述】:
在 JPA2 中,当我们在使用 @ElementCollection 和 @CollectionTable 注释的实体中使用 Embed-able (Basic Type like String.. etc ) 对象时,会创建新表,但在新表中如何声明主键约束在列?以下是我的代码
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String name;
private String salary;
@Transient
private String phnNum;
@Enumerated(EnumType.STRING)
private EmployeeType type;
@ElementCollection
@CollectionTable(name="vacations" , joinColumns=@JoinColumn(name="Emp_Id"))
private Collection<Vacation> vacationBooking;
@ElementCollection
private Set<String> nickNames;
...................
使用此代码,“vacation”和“employee_nickname”两个表在模式中创建。但我想在两个表中声明一个主键列。我为此做什么?
【问题讨论】:
-
能否把完整的代码,包括Vacation类的代码放上来?
标签: java hibernate jpa annotations jpa-2.0