我有两个班级:
@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
)加入。怎么做?
我知道最好使用主键加入,但数据库结构已修复,我无法更改。
答案 0 :(得分:0)
尝试:
@OneToOne
@Column(name = "client_name")
@JoinColumn(name = "client_name", referencedColumnName = "name")
public Client client;