其他分享
首页 > 其他分享> > @OneToOne

@OneToOne

作者:互联网

@Entity
@Getter
@Setter
@Table(name="tb_participant")
public class ParticipantEntity extends MappingEntity implements Serializable {
    private static final long serialVersionUID = 276431614574466988L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name="participant_id", referencedColumnName = "id", insertable = false, updatable = false)
    private List<StandingInstructionEntity> ssiList;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="id", referencedColumnName = "id", insertable = false, updatable = false)
    private PartOtherInfoEntity otherInfo;
}    
@MappedSuperclass
@Getter
@Setter
public class MappingEntity implements Serializable {
    @Column(name = "created_by")
    private String createUserId;

    @Column(name = "created_date", updatable = false, insertable = false)
    private Date createDt;

    @Column(name = "updated_by")
    private String updateUserId;

    @Column(name = "updated_date", updatable = false, insertable = false)
    private Date updateDt;

}
  1. @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name=“participant_id”, referencedColumnName = “id”, insertable = false, updatable = false)

这里@JoinColumn()中name="participant_id"指子表中的字段, referencedColumnName = "id"指当前表中的字段

  1. @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name=“id”, referencedColumnName = “id”, insertable = false, updatable = false)
    这里的name=“id”, 指的当前表的字段(可以是任意名字的字段),referencedColumnName = "id"只能是子表的主键id.

标签:false,OneToOne,insertable,private,updatable,id,name
来源: https://blog.csdn.net/weixin_43126564/article/details/120823917