繁体   English   中英

Java jpa:@OneToOne

[英]Java jpa: @OneToOne

我在使用 JPA 时遇到问题。

我想fatherId和father共存,当我用join表查询的时候。

@Entity
public class Son {

    @Id
    @Column(name = "id")
    private String id;

    
    
    @Column(name = "father_id")
    private String fatherId;


    @OneToOne
    @JoinColumn(name = "father_id")
    private Father father;
}

您必须将其中一个设置为只读。

例如:

@Column(name = "father_id", insertable = false, updatable = false)
private String fatherId;

@OneToOne
@JoinColumn(name = "father_id")
private Father father;

否则Hibernate有两种写外键的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM