我有 2 个对象Customer
和CustomerAcctSetting
. CustomerAcctSetting
有外键CUSTOMER_ID
。我的问题是当我得到一个Customer
对象时,我无法获得关联的对象CustomerAcctSetting
并且只返回 null。
下面是2个休眠对象:
Customer.java
@Entity
@Table(name = "CUSTOMER")
public class Customer extends BaseDomain{
.
.
.
private CustomerAcctSetting customerAcctSetting;
@Id
@Override
@GeneratedValue(generator = "increment")
@GenericGenerator (name = "increment", strategy = "increment")
@Column (name = "CUSTOMER_ID", unique = true, nullable = false, insertable = false, updatable = false)
public int getId() {
return super.getId();
}
.
.
.
@OneToOne
@JoinColumn(name = "CUSTOMER_ID")
public CustomerAcctSetting getCustomerAcctSetting() {
return customerAcctSetting;
}
public void setCustomerAcctSetting(CustomerAcctSetting customerAcctSetting) {
this.customerAcctSetting = customerAcctSetting;
}
}
CustomerAcctSetting.java
@Entity
@Table(name = "CUSTOMER_ACCT_SETTING")
public class CustomerAcctSetting extends BaseDomain{
private int customerId;
.
.
.
@Id
@Override
@GeneratedValue(generator = "increment")
@GenericGenerator (name = "increment", strategy = "increment")
@Column (name = "CUSTOMER_ACCT_SETTING_ID", unique = true, nullable = false, insertable = false, updatable = false)
public int getId() {
return super.getId();
}
.
.
.
@Column(name = "CUSTOMER_ID")
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
}
我没有在 中包含任何映射,Customer
因为CustomerAcctSetting
我不必Customer
从CustomerAcctSetting
. 我只放CUSTOMER_ID
了CustomerAcctSetting
.
请帮忙。提前致谢。