1

私は2つのオブジェクトCustomerCustomerAcctSetting. CustomerAcctSettingは外部キーを持っていますCUSTOMER_ID。私の問題はCustomer、関連付けられたオブジェクトを取得できず、CustomerAcctSettingnull のみを返すオブジェクトを取得することです。

以下は、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、 のマッピングは含めませんでした。だけ入れました。CustomerAcctSettingCustomerCustomerAcctSettingCUSTOMER_IDCustomerAcctSetting

助けてください。前もって感謝します。

4

1 に答える 1

2

inを使用してこれを解決し、mappedBy="Customer"inとCustomerを追加しましCustomerた。CustomerAcctSetting@JoinColumn

以下はクラスです:

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(mappedBy="customer")
    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 Customer customer;
    .
    .
    .

    @OneToOne
    @JoinColumn (name="CUSTOMER_ID", insertable=false, updatable=false)
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
}
于 2013-01-10T03:23:37.490 に答える