简体   繁体   English

Java jpa:@OneToOne

[英]Java jpa: @OneToOne

I have a problem using JPA.我在使用 JPA 时遇到问题。

I want to the fatherId and father coexistence,When I query with join table.我想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;
}

You have to set one to read-only.您必须将其中一个设置为只读。

For example:例如:

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

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

Otherwise Hibernate has two ways to write the foreign key.否则Hibernate有两种写外键的方法。

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

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