java - 带接口(interface)的 Hibernate HQL

标签 java hibernate orm hql entity

根据 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/

相关文章:

java - 如何为抽象类的子类声明默认构造函数?

java - 椭圆曲线中的点乘

java - JSF + Primefaces : Ajax CRUD-Actions in Master-Detail-View only work once per page-load

entity-framework - Entity Framework 与普通 ORM 有何不同?

c# - 请推荐.NET ORM进行N层开发

java - while循环初始化但不循环java

java - 在 Java 中,如何测试 `Double` 列表是否包含特定值

java - HQL错误 "Could not resolve property"

java - 两个实体上的 JPA/Hibernate 双向 Set<Object>

java - 必须为元素类型属性声明属性值