Hibernate Queries - II

2 May 2008

In this post, I will continue presenting HQL tips and trick that will help you in development.

The following query may return multiple objects as an array of type Object[].

select mother, offspr, mate.name 
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr

Now suppose, you would like to get a list in theabove scnario - use the following query:

select new list(mother, offspr, mate.name)
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr

One may need type safe Java object as result.

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

This is the beauty of Hibernate. You can get data fetched from database tables in form of list, objects or arrays. This is useful in complex applications.

Do read the next posts on this very topic.

del.icio.us:Hibernate Queries - II  digg:Hibernate Queries - II  spurl:Hibernate Queries - II  wists:Hibernate Queries - II  simpy:Hibernate Queries - II  newsvine:Hibernate Queries - II  blinklist:Hibernate Queries - II  furl:Hibernate Queries - II  reddit:Hibernate Queries - II  fark:Hibernate Queries - II  blogmarks:Hibernate Queries - II  Y!:Hibernate Queries - II  smarking:Hibernate Queries - II  magnolia:Hibernate Queries - II  segnalo:Hibernate Queries - II  gifttagging:Hibernate Queries - II

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Hibernate Queries - II

Leave a Reply