0

给定的是以下表结构,我无法更改:

Table A {
    idA auto_increment primary key
    [... some values...]
}

Table B {
    idB auto_increment primary key
    idA foreign key referencing Table A
    [... some values...]
}

Table C {
    idC auto_increment primary key
    idA foreign key referencing Table A
    [... some values...]
}

我想将这些表映射到一个抽象超类和两个子类,如下所示:

@Inheritance(strategy = InheritanceType.JOINED)
public abstract class A {
    @Id
    @GeneratedValue(strategy=IDENTITY)
    private int aID;

}

@PrimaryKeyJoinColumn (name = "idA")
public class B extends A {

    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int bID;

}

@PrimaryKeyJoinColumn (name = "idA")
public class C extends A {

    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int cID;

}

看来这些注解不正确,hibernate无法处理子类中的两个ID。

假设给定的表结构不能更改,将表结构映射到类结构的最佳方法是什么?

4

0 回答 0