java hibernate:在多态hql查询中选择鉴别器列

时间:2021-01-05 01:33:11

In hibernate, I want to select the discriminator value. Something like

在hibernate中,我想选择discriminator值。类似的

select discriminator, id, name, age from Animal

从动物中选择鉴别器、身份、姓名、年龄

The idea is to send the result of this query to the client side, so that I can display a different icon based on the value of the discriminator column (i.e. cat, dog, elephant, etc).

我们的想法是将这个查询的结果发送到客户端,这样我就可以根据discriminator列(比如cat、dog、elephant等)的值显示不同的图标。

Is that possible? How?

这有可能吗?如何?

2 个解决方案

#1


27  

You can do it as follows:

你可以这样做:

select a.class, a.id, a.name, a.age from Animal a

From Hibernate Documentation:

从Hibernate文档:

The special property class accesses the discriminator value of an instance in the case of polymorphic persistence.

在多态持久化的情况下,特殊属性类访问实例的鉴别器值。

#2


1  

Hibernate query objects, does not know columns. So unless you have a property named discriminator in your Animal object you cant do that. You can do the query in sql or get the entire object and then to get the inherited type, for that you can use "instanceof"

Hibernate查询对象,不知道列。所以,除非你在你的动物对象中有一个名为鉴别器的属性,否则你不能这么做。你可以用sql进行查询或者获取整个对象然后获取继承的类型,你可以使用"instanceof"

#1


27  

You can do it as follows:

你可以这样做:

select a.class, a.id, a.name, a.age from Animal a

From Hibernate Documentation:

从Hibernate文档:

The special property class accesses the discriminator value of an instance in the case of polymorphic persistence.

在多态持久化的情况下,特殊属性类访问实例的鉴别器值。

#2


1  

Hibernate query objects, does not know columns. So unless you have a property named discriminator in your Animal object you cant do that. You can do the query in sql or get the entire object and then to get the inherited type, for that you can use "instanceof"

Hibernate查询对象,不知道列。所以,除非你在你的动物对象中有一个名为鉴别器的属性,否则你不能这么做。你可以用sql进行查询或者获取整个对象然后获取继承的类型,你可以使用"instanceof"