Hibernate HQL与接口 [英] Hibernate HQL with interfaces
问题描述
http://docs.jboss.org/hibernate/core/3.3/reference/en/html /queryhql.html#queryhql-polymorphism
不幸的是,当我运行这个查询时......
<$从交易trans其中trans.envelopeId =:envelopeId
事务是一个接口,我必须实体类实现它,我希望在HQL查询中返回一个Collection类型的Transaction。 的确,根据Hibernate文档< a href =http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-polymorph hibernate查询可以命名任何Java 接口Named可能是 但是因为接口没有被映射(因此未知),所以您需要在HQL查询中使用完全限定名称: 这个将返回实现您的 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... I get the message "Transaction is not mapped [from Transaction trans where trans.envelopeId=:envelopeId]". Transaction is an interface, I have to entity classes that implement it, I want on HQL query to return a Collection of type Transaction. Indeed, according to the Hibernate documentation on Polymorphic queries: 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: The interface Named might be
implemented by various persistent
classes:
But because the interface is not mapped (and thus unknown), you need to use the fully qualified name in your HQL query: This will return instances of all persistent classes that implement your 这篇关于Hibernate HQL与接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! >我得到消息事务没有被映射[来自事务trans其中trans.envelopeId =:envelopeId]。
类或接口在from子句中。
查询将返回所有
持久化类的实例,这些类扩展了
类或实现了接口。
以下查询将返回所有
持久对象:
来自java.lang.Object o
,由各种持久
类实现:
from Named n,Named m where n.name = m.name
$ b 来自qualified.name.Transaction trans其中trans.envelopeId =:envelopeId
Transaction
接口的所有持久化类的实例。"from Transaction trans where trans.envelopeId=:envelopeId"
from java.lang.Object o
from Named n, Named m where n.name = m.name
from qualified.name.Transaction trans where trans.envelopeId=:envelopeId
Transaction
interface.