继承 类 上的 Hibernate 嵌套鉴别器
Hibernate nested discriminator on inherited classes
我有 2 MYSQL 个表
表1
id bigint auto increment Primary Key
type Enum ('vegetable','fruit')
color Enum ('green','red','yellow')
table2
id bigint (same as the id in Table 1)
sweet boolean
sour boolean
.. other fields specific to type fruit
现在我正在创建 3 个对象,首先是父对象 class
@Entity
@Configurable
@Table(name = "table1")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public class ParentClass {
..
}
现在第二个class蔬菜
@Entity
@Configurable
@DiscriminatorValue("vegetable")
@DiscriminatorColumn(name = "color", discriminatorType = DiscriminatorType.STRING)
public class Vegetable extends Parent{
..
}
第三,水果class
@Entity
@Configurable
@SecondaryTables({ @SecondaryTable(name = "table2",
pkJoinColumns = { @PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id") }) })
@DiscriminatorValue("fruit")
@DiscriminatorColumn(name = "color", discriminatorType = DiscriminatorType.STRING)
public class Fruit extends Parent{
..
}
我需要第二个鉴别器在 Vegetable 和 Fruit 上添加进一步继承的 classes(另外 6 个 classes),例如
@Entity
@Configurable
@DiscriminatorValue("red")
public class RedVegetable extends Vegetable{
..
}
@Entity
@Configurable
@DiscriminatorValue("green")
public class GreenFruit extends Fruit{
..
}
等等。
Hibernate 不允许我这样做。我的设计有什么问题?提前致谢!
了解到这不能在 Hibernate 中完成。因此找到了一种替代方法,通过合并表 1 中的鉴别器朋友,如枚举('fruit|red'、'fruit|green'、'vegetable|red'.. 等等)。
如果我错了,请纠正我。
我有 2 MYSQL 个表
表1
id bigint auto increment Primary Key
type Enum ('vegetable','fruit')
color Enum ('green','red','yellow')
table2
id bigint (same as the id in Table 1)
sweet boolean
sour boolean
.. other fields specific to type fruit
现在我正在创建 3 个对象,首先是父对象 class
@Entity
@Configurable
@Table(name = "table1")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public class ParentClass {
..
}
现在第二个class蔬菜
@Entity
@Configurable
@DiscriminatorValue("vegetable")
@DiscriminatorColumn(name = "color", discriminatorType = DiscriminatorType.STRING)
public class Vegetable extends Parent{
..
}
第三,水果class
@Entity
@Configurable
@SecondaryTables({ @SecondaryTable(name = "table2",
pkJoinColumns = { @PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id") }) })
@DiscriminatorValue("fruit")
@DiscriminatorColumn(name = "color", discriminatorType = DiscriminatorType.STRING)
public class Fruit extends Parent{
..
}
我需要第二个鉴别器在 Vegetable 和 Fruit 上添加进一步继承的 classes(另外 6 个 classes),例如
@Entity
@Configurable
@DiscriminatorValue("red")
public class RedVegetable extends Vegetable{
..
}
@Entity
@Configurable
@DiscriminatorValue("green")
public class GreenFruit extends Fruit{
..
}
等等。
Hibernate 不允许我这样做。我的设计有什么问题?提前致谢!
了解到这不能在 Hibernate 中完成。因此找到了一种替代方法,通过合并表 1 中的鉴别器朋友,如枚举('fruit|red'、'fruit|green'、'vegetable|red'.. 等等)。 如果我错了,请纠正我。