gpt4 book ai didi

java - JPA,将复杂数据类型放在同一个表的实体内

转载 作者:行者123 更新时间:2023-12-02 03:11:14 24 4
gpt4 key购买 nike

我有一个类 Customer,它是一个实体:@实体

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

最佳答案

将 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;
...
}

关于java - JPA,将复杂数据类型放在同一个表的实体内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41014712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com