【问题标题】:can you please tell why one to one bi direction mapping is not working你能告诉我为什么一对一双向映射不起作用吗
【发布时间】:2023-01-14 01:44:49
【问题描述】:

`@实体 @Table(name = "学生") 公开课学生{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

@Column(name = "email")
private String email;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "student_detail_id")
private StudentDetail studentDetail;

public Student() {}

//getters setters`

`@实体 @Table(name = "student_detail") 公开课 StudentDetail {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column(name = "college")
private String college;

@Column(name = "no_of_problems_solved")
private int noOfProblemsSolved;

public StudentDetail() {}
@Column(name = "college")
private String college;

@Column(name = "no_of_problems_solved")
private int noOfProblemsSolved;

public StudentDetail() {}``

你能告诉我为什么一对一双向映射不起作用吗

【问题讨论】:

  • 不管用方法?

标签: spring


【解决方案1】:

在 Student_Detail 中,您还必须指定 @OntToOne 注释。

@Entity
@Table(name = "student_detail")
public class StudentDetail {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

    @Column(name = "college")
    private String college;

    @Column(name = "no_of_problems_solved")
    private int noOfProblemsSolved;

    @OneToOne(mappedBy = "studentDetail", cascade = CascadeType.ALL)
    private Student student;
    //Getters setters
}

这应该适合你。 希望这可以帮助。

【讨论】:

    猜你喜欢
    • 2015-09-12
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 2010-12-12
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多