Hibernate 继承映射中的多个 DiscriminatorColumn
我了解了如何在 Hibernate 继承映射中使用 DiscriminatorColumn, 然而,在我的场景中,我有更复杂的继承模块,我需要定义两个鉴别器。我想为整个继承树使用一张表。 基本上,父类是抽象的,它代表一个人实体, 然后,我有它的两个不同的抽象实现,Wife 和 Wife 。丈夫。所以基本上我已经需要一个鉴别器了。那么对于每个(妻子和丈夫)我都有不同的消息需要保留,所以我不需要为每个(妻子和丈夫)创建一个鉴别器。
我想出了这个实现,但我陷入困境,我该如何从这里继续?
@Entity
@Table (name="sex")
@Inheritance (strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn (name="transaction_type", discriminatorType=DiscriminatorType.STRING)
public abstract class Person {
...
}
@Entity
@DiscriminatorValue("wife")
public class Wife extends Person {
...
}
现在,我如何在 Wife 类上放置一个鉴别器列,就像我对 Parent 所做的那样?
I understood how to use DiscriminatorColumn in Hibernate inheritance mapping,
However, in my scenario, I have more complicated inheritance module, where I need to define two Discriminators. I want to use one table for the entire inheritance tree.
Basically, the parent class is abastract, and it represents a person entity,
then, I have two different abstract implementation of it, Wife & Husband. so basically I already need one discriminator. then for each (Wife & Husband) I have different messages that needs to be persisted, so I need no to create a discriminator for each (Wife & Husband).
I came up with this implementation, but I'm stuck, how do I continue from here ?
@Entity
@Table (name="sex")
@Inheritance (strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn (name="transaction_type", discriminatorType=DiscriminatorType.STRING)
public abstract class Person {
...
}
@Entity
@DiscriminatorValue("wife")
public class Wife extends Person {
...
}
now, how do I put a discriminatorcolumn on the Wife Class, the same as I did with the Parent ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要第二个鉴别器。
Wife
实体将正常工作。在二级继承的情况下,中产阶级(在这种情况下是妻子和丈夫)不需要有
@DiscriminatorColumn
。相关问题2级继承的问题可能乐于助人。
另一个问题Hibernate Inheritance Single_table
You don't need the seccond discriminator. the
Wife
Entity will work correctly.In 2-level inheritance situations, the middle classes (wife and husband in this case) does not nead to have
@DiscriminatorColumn
.the related question Problem with 2 levels of inheritance may be helpful.
the other question Hibernate Inheritance Single_table