Hibernate HQL with interfaces

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"

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

Transaction is an interface, I have entity classes that implement it, I want a collection of type Transaction to be returned in the HQL query.

+3
source share
3 answers

, Hibernate :

Java from. , . :

from java.lang.Object o

:

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

( ), HQL:

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

, Transaction.

+11

, . imports.hbm.xml :

<hibernate-mapping package="com...path.to.implementations">
  <import class="com.path.to.interfaces.Transaction" rename="Transaction"/>
...
</hibernate-mapping>

, .

+1

I think you need to display the interface as a parent class and implementation classes as your subclass.

http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#inheritance-strategies

0
source

Source: https://habr.com/ru/post/1733636/


All Articles