根据 Hibernate 文档的这一部分,我应该能够查询 HQL 中的任何 java 类
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-polymorphism
不幸的是,当我运行这个查询时...
"from Transaction trans where trans.envelopeId=:envelopeId"
我收到消息“事务未映射 [来自 Transaction trans where trans.envelopeId=:envelopeId]”。
Transaction 是一个接口(interface),我必须实现它的实体类,我希望 HQL 查询返回一个类型为 Transaction 的 Collection。
最佳答案
的确,根据 Polymorphic queries 上的 Hibernate 文档:
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
The interface Named might be implemented by various persistent classes:
from Named n, Named m where n.name = m.name
但由于接口(interface)未映射(因此未知),您需要在 HQL 查询中使用完全限定名称:
from qualified.name.Transaction trans where trans.envelopeId=:envelopeId
这将返回实现您的Transaction
接口(interface)的所有持久化类的实例。
关于java - 带接口(interface)的 Hibernate HQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301147/