2016-12-07 27 views
0

我有一类客户是一个实体: @EntityJPA,将复杂的数据类型的实体内同一表

public class Customer { 
@Id 
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="customerId_Sequence") 
@SequenceGenerator(name="customerId_Sequence",sequenceName="CUSTOMER_SEQ",allocationSize=1) 
private long customerId; 
private String firstName; 
private String lastName; 
private BillingDetails billingDetails 

我有一个类BillingDetails,看起来像这样:

public class BillingDetails { 
private String type; 
private long ccNumber; 

我使用hibernate作为我的持久性提供者。我希望它在sql中创建一个表,其中有列customerId,firstName,lastName,type,ccNumber。我希望将它全部放在一张表中,我不希望账单细节成为实体。这可能吗?

当我尝试这样我得到一个错误:无法确定类型:**** BillingDetails

回答

2

型号BillingDetails为@Embeddable。

@Entity 
public class Customer { 
@Id 
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="customerId_Sequence") 
@SequenceGenerator(name="customerId_Sequence",sequenceName="CUSTOMER_SEQ",allocationSize=1) 
private long customerId; 
private String firstName; 
private String lastName; 

@Embedded 
private BillingDetails billingDetails; 
... 
} 



@Embeddable 
public class BillingDetails { 
private String type; 
private long ccNumber; 
... 
}