开发者

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?


The Family is a plain POJO with the appropriate constructor which either needs to be declared or fully qualified.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜