How does the new keyword work in hql?

I found this example in the jboss documentation.

select new Family(mother, mate, offspr)
from DomesticCat as mother
    join mother.mate as mate
    left join mother.kittens as offspr

Where did the class come from Family. Do I need to import somewhere or use its fully qualified class name?

+3
source share
3 answers

Family is a simple POJO with an appropriate constructor that must either be declared or fully qualified.

+3
source

Familymust be a Java object with an appropriate constructor. Import is optional if the object is a normal display object (either using annotations or in XML sleep format).

+2
source

, .: -)

Yes, it must exist. This is a class that is not an entity; you create it to handle three columns in an understandable way. He needs a constructor suitable for calling.

Basically, this is similar to what you did:

  • query that returns a List (with three columns)
  • in the list, creates a Family object containing the columns and returns a list of these results.
+1
source

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


All Articles