[英]Hibernate criteria query in multiple levels of entity inheritance
如果您以single_table方式具有多個繼承級別,例如class
class LivingCreatures {},
class Animals extends LivingCreatures {},
class Dog extends Animals {},
class Cat extends Animals {}
我注意到,數據庫層中只有一個鑒別符列。
有沒有辦法向所有動物詢問LivingCreatures?
session().createCriteria(LivingCreatures.class).add(
Restrictions.eq("class", Animals.class)
)
我認為這應該工作
session.createCriteria(LivingCreatures.class, "creatures").add(Restrictions.eq("creatures.class", Animals.class));
這將只返回LivingCreatures
其dtype
是Animals
,而不會返回Dog
S或Cat
秒。 如果您希望所有Animals
包括子類型)都可以使用createCriteria(Animals.class
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.