2015-05-20 11 views
11

Mam tabelę kontroli z poprawkami i chcę utworzyć kolejną tabelę z relacją jeden-do-wielu z wersją tabeli kontroli. Wersja audytu wskaże nowe dane w tabeli. Jak mogę to zrobić?Tabela łączenia hibernacji z inną tabelą kontroli

+0

zobacz moją odpowiedź na od http://stackoverflow.com/q/30184227/845849 –

+0

Nie chcę zmieniać tabeli revinfo, chcę tylko użyć wersji jako relacji z inną tabelą. –

+0

Ahh w porządku, w takim przypadku można po prostu odwzorować domyślną encję rewizji (org.hibernate.envers.DefaultRevisionEntity) w wymaganej tabeli encji. –

Odpowiedz

2

Zrobiłem coś podobnego w projekcie, który ma GPA studentów (tabela audytu z poprawkami), a następnie tabelę z CurrentGpa, która zawsze wskazuje na wersję wiodącą z tabeli GPA. Aby to zrobić kiedyś następującą strukturę:

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

    // ... 
} 
Powiązane problemy