简体   繁体   English

hql中的new关键字如何工作?

[英]how does the new keyword in hql work?

I found this example in jboss's documentation. 我在jboss的文档中找到了这个例子。

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. Family班来自何处。 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. Family必须是具有适当构造函数的Java对象。 The import is optional if the object is a normal mapped entity (either using using annotations or in a hibernate mapping XML). 如果对象是普通的映射实体(使用注释或使用hibernate映射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) 返回List的查询(带有三列)
  • loop on the list, creates a Family object holding the columns, and return the list of these results 在列表上循环,创建一个包含列的Family对象,并返回这些结果的列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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