如何使用二级密钥加入OneToOne关系?

时间:2013-01-21 07:55:46

标签: java jpa orm playframework-2.0 ebean

我有两个班级:

@Entity
@Table(name = "clients")
public class Client extends Model {

    @Id
    public int id;

    public String name;

    @OneToOne
    public Contact contact;
}

@Entity
@Table(name = "contacts")
public class Contact extends Model {

    @Id
    public int id;

    @OneToOne
    @Column(name = "client_name")
    public String clientName;
}

现在我想设置OneToOne关系,但是使用client_name列(on clients.name=contacts.client_name)加入。怎么做?

我知道最好使用主键加入,但数据库结构已修复,我无法更改。

1 个答案:

答案 0 :(得分:0)

尝试:

@OneToOne
@Column(name = "client_name")
@JoinColumn(name = "client_name", referencedColumnName = "name")
public Client client;