gpt4 book ai didi

hibernate 连接表与其他审计表

转载 作者:行者123 更新时间:2023-12-04 01:13:29 25 4
gpt4 key购买 nike

我有一个带有修订的审计表,我想创建另一个与审计表修订具有一对多关系的表。审计修订将指向新表数据。我怎样才能做到这一点?

最佳答案

我在一个项目中做了类似的事情,该项目有学生 GPA(带修订的审计表),然后是一个带有 CurrentGpa 的表。它始终指向 GPA 的主要修订版 table 。为此,我使用了以下结构:

CurrentGpa.java

@Entity(name = HibernateConsts.CURRENT_GPA_TABLE)
public class CurrentGpa {
protected Gpa gpa;
protected Student student;
protected Long id;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = HibernateConsts.CURRENT_GPA_ID)
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@OneToOne(optional = true, fetch= FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = HibernateConsts.GPA_FK)
public Gpa getGpa() {
return gpa;
}

public void setGpa(Gpa gpa) {
this.gpa = gpa;
}

@OneToOne(optional = true, fetch= FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = HibernateConsts.STUDENT_FK)
public Student getStudent() {
return student;
}

public void setStudent(Student student) {
this.student = student;
}

// ...
}

Gpa.java
@Entity(name = HibernateConsts.GPA_TABLE)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Gpa {
protected Long studentId;
protected Double score;
protected LocalDate startDate;
protected LocalDate endDate;
protected LocalDate calculationDate;
protected Long id;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = HibernateConsts.GPA_ID)
public Long getId() { return id; }

public void setId(Long id) {
this.id = id;
}

@Column(name = HibernateConsts.STUDENT_FK)
public Long getStudentId() {
return studentId;
}

public void setStudentId(Long studentId) {
this.studentId = studentId;
}

@Column(name = HibernateConsts.GPA_SCORE)
public Double getScore() {
return score;
}

public void setScore(Double score) {
this.score = score;
}

@Column(name = HibernateConsts.GPA_START_DATE)
public LocalDate getStartDate() {
return startDate;
}

public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}

@Column(name = HibernateConsts.GPA_END_DATE)
public LocalDate getEndDate() {
return endDate;
}

// ...
}

关于 hibernate 连接表与其他审计表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30353192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com