简体   繁体   中英

how does the new keyword in hql work?

I found this example in jboss's documentation.

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

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

Family是一个简单的POJO,具有适当的构造函数,需要声明或完全限定。

Family must be a Java object that has an appropriate constructor. The import is optional if the object is a normal mapped entity (either using using annotations or in a hibernate mapping XML).

The import is optional, if it is found for another reason. :-)

Yes, it needs to exist. It is a class that is not an entity, you create it to handle in a intelligible way the three columns. It needs a constructor appropriate for the call.

Basically, it is like if you did:

  • a query that returns List (with the three columns)
  • loop on the list, creates a Family object holding the columns, and return the list of these results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM