1、“optional=true” 即表示被维护一方可有可无,并不是必须的,比较Customer----ContactInfo,即联系方式可以没有。

@OneToOne(cascade=CascadeType.ALL,optional=true)
    public ContactInfo getContactInfo() {
        return contactInfo;
    }
    public void setContactInfo(ContactInfo contactInfo) {
        this.contactInfo = contactInfo;
    }


2、Customer(1)----ContactInfo(0...1)的配置如下:

Customer(1)类:

@OneToOne(cascade=CascadeType.ALL,optional=true)
@JoinColumn(name="contact_id")           //外键
public ContactInfo getContactInfo() {
    return contactInfo;
}
public void setContactInfo(ContactInfo contactInfo) {
    this.contactInfo = contactInfo;
}

ContactInfo(0...1) 类:

@OneToOne(mappedBy = "contactInfo", cascade = CascadeType.REFRESH)
public Customer getCustomer() {
    return customer;
}
public void setCustomer(Customer customer) {
    this.customer = customer;
}