-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Converting results of Hibernate Query to bean type
PostPosted: Mon Nov 23, 2009 5:53 pm 
Newbie

Joined: Fri Nov 20, 2009 10:56 am
Posts: 3
Hi All,

I have an HQL Query shown below that I execute with createQuery:

Code:
   sb.append("select D.defectId, D.description, P.description as Priority, D.reportDateTime as ReportDate, S.userName as
      Reporter, FA.areaName as FunctionalArea, ST.description as Status, D.severity as Severity From Defect as D ");
   sb.append("JOIN D.stf1 as S ");
   sb.append("JOIN D.priorities as P ");
   sb.append("JOIN D.statuses as ST ");
   sb.append("JOIN D.functionalAreas as FA");     
            
   results = session.createQuery(sb.toString()).list();   



The results are an ArrayList of objects. However, what I really want is to convert this ArrayList of Objects into my (specific) bean type? In this case the bean type is Defect. Do I have to do this conversion manually or is there some easier way? I'm new to Hibernate so I could easily be missing something.

Thanks for your help,

Rob


Top
 Profile  
 
 Post subject: Re: Converting results of Hibernate Query to bean type
PostPosted: Tue Nov 24, 2009 5:23 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
just try
Code:
select d from Defect d...

and have a look at the reference.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Converting results of Hibernate Query to bean type
PostPosted: Tue Nov 24, 2009 5:34 pm 
Newbie

Joined: Fri Nov 20, 2009 10:56 am
Posts: 3
Hi,

What I'm trying to ask is if I have this HQL (Join) Query:

Code:
   sb.append("select D.defectId, D.description, P.description as Priority, D.reportDateTime as ReportDate, S.userName as 
   Reporter, FA.areaName as FunctionalArea, ST.description as Status, D.severity as Severity From Defect as D ");
   sb.append("JOIN D.stf1 as S ");
   sb.append("JOIN D.priorities as P ");
   sb.append("JOIN D.statuses as ST ");
   sb.append("JOIN D.functionalAreas as FA");     


and I have a class called "DisplayDefect" that is created to hold the results and I execute the query like this:

Code:
   results = session.createQuery(sb.toString()).list(); 


What is the easiest way to get the DisplayDefect Class populated with the results?

I think if I use a native query I can just do this:

Code:
   results = session.createSQLQuery(sql).addEntity(DisplayDefect.class).list();


and this will give me an array of DisplayDefect Objects . . . and I can do this I suppose but how do I do it if I execute a "non-native" query . . . that is an HQL Query?

Thanks,

Rob


Top
 Profile  
 
 Post subject: Re: Converting results of Hibernate Query to bean type
PostPosted: Wed Nov 25, 2009 4:44 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
you could use row value constructor syntax.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.