views:

92

answers:

3

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?

+3  A: 

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

Pascal Thivent
Declared where? How?
flybywire
@flybywire As entity (annotated or mapped)
Pascal Thivent
+1  A: 

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
KLE
if the import is optional and the class is not an entity, how will Hibernate find it? In which packages will it look for it?
flybywire
@Flybywire True, it has to be found in some way :-). It is found if declared an an entity, if in a default package for Hibernate, or if imported. I was not very clear in my answer, because it is true that Entities are always in the first case. :-)
KLE
+2  A: 

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).

Tendayi Mawushe