spring 你能告诉为什么一对一双向Map不工作吗

rpppsulh  于 2023-01-16  发布在  Spring
关注(0)|答案(1)|浏览(152)

'@实体@表(name ="student")公共类学生{

@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() {}

//获取器设置器'
'@实体@表(名称="学生明细")公共类学生明细{

@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() {}``

你能告诉为什么一对一双向Map不工作吗

lsmepo6l

lsmepo6l1#

在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
}

这应该对你有用。

相关问题