带接口的 Hibernate HQL [英] Hibernate HQL with interfaces

查看:28
本文介绍了带接口的 Hibernate HQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Hibernate 文档的这一部分,我应该能够在 HQL 中查询任何 java 类

According to this section of the Hibernate documentation I should be able to query any java class in HQL

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-polymorphism

不幸的是,当我运行此查询时...

Unfortunately when I run this query...

"from Transaction trans where trans.envelopeId=:envelopeId"

我收到消息事务未映射 [来自事务 trans where trans.envelopeId=:envelopeId]".

I get the message "Transaction is not mapped [from Transaction trans where trans.envelopeId=:envelopeId]".

Transaction 是一个接口,我必须实现它的实体类,我希望 HQL 查询返回类型为 Transaction 的集合.

Transaction is an interface, I have to entity classes that implement it, I want on HQL query to return a Collection of type Transaction.

推荐答案

确实,根据 多态查询:

Hibernate 查询可以命名任何 Javafrom 子句中的类或接口.查询将返回所有实例扩展它的持久类类或实现接口.这以下查询将返回所有持久对象:

Hibernate queries can name any Java class or interface in the from clause. The query will return instances of all persistent classes that extend that class or implement the interface. The following query would return all persistent objects:

from java.lang.Object o

接口 Named 可能是由各种持久化实现类:

The interface Named might be implemented by various persistent classes:

from Named n, Named m where n.name = m.name

但由于接口未映射(因此未知),您需要在 HQL 查询中使用完全限定名称:

But because the interface is not mapped (and thus unknown), you need to use the fully qualified name in your HQL query:

from qualified.name.Transaction trans where trans.envelopeId=:envelopeId

返回实现您的Transaction接口的所有持久类的实例.

This will return instances of all persistent classes that implement your Transaction interface.

这篇关于带接口的 Hibernate HQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆