-->
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.  [ 3 posts ] 
Author Message
 Post subject: using hibernate to populate a non-persistent object
PostPosted: Mon Nov 29, 2004 10:24 am 
Newbie

Joined: Wed Jul 14, 2004 11:38 am
Posts: 3
Session.createSQLQuery requires that the returned object be of a persistent class.

is there a way of running an sql so that hibernate populates a regular bean (meaning, unknown to hibernate) with the result set values?

for example, say i have a table foo:

i want to run this:
select count(foo.type), foo.type from foo group by foo.type;

now, i want to use hibernate's mapping power, so that i do something along these lines:
1. create a FooCount class:
public class FooCount {
int count;
int type;

// getters and setters
}

2. use something like Session.createSQLQuery, which returns a collection with instances of FooCount with the right values.


thank you for your help!
ittay


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 10:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Not possible with createSQLQuery. You can use select new() in HQL though.


Top
 Profile  
 
 Post subject: using hibernate to populate a non-persistent object
PostPosted: Tue Nov 30, 2004 1:50 am 
Newbie

Joined: Wed Jul 14, 2004 11:38 am
Posts: 3
but hql doesn't have the power of sql. things like 'count(! is_foo)' are not supported.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.