-->
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: HQL query with select new on class and also property
PostPosted: Thu Aug 04, 2005 4:54 pm 
Beginner
Beginner

Joined: Tue Apr 12, 2005 9:15 pm
Posts: 24
I am not sure whether this is possible to do. I have an HQL query this does "select distinct c from Class1 c, Class2 d where c.column1 = d.column2". That works fine, but now I have a property on Class1 that is not persisted in the database, however, when I do the same HQL query, I want to populate the value for that dynamic property from Class2's "column2" property value on Class1 object that I am selecting. Is this possible?


Top
 Profile  
 
 Post subject: ?
PostPosted: Thu Aug 04, 2005 5:23 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
according to you sql value of c.column1 (and corresponding property in th object) hasa the same value as column2.
So, what exactly are you trying to accomplish?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 6:30 pm 
Beginner
Beginner

Joined: Tue Apr 12, 2005 9:15 pm
Posts: 24
yes sorry - On Class1 I have a property "class1property1" that is not persisted in database. And by doing this query, from Class2's "column3" property, I want to set the class1property1. I think I need to use select new Class1 (.....) and have the Class1's constructor take care of setting the property. Do you see any other way?


Top
 Profile  
 
 Post subject: select new
PostPosted: Thu Aug 04, 2005 7:11 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
select new Class could work, but you will need to have to have all other (persistent) properties defined as constructor parameters, which is hard to write and maintain.

Could you return that extra property in the select and then postprocess the result.

select c, d.prop1 from Class1 c, Class2 d where c.column1 = d.column2

The select will return object arrays for every row where first element is object of class Class1, and second is the value of d.prop1


List result = new ArrayList()l
for( Object[] row : list){
Class1 c = (Class1) row[0];
Integer v = (Integer) row[1];
c.set( v )
result.add(c);
}


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.