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: Native SQL query mapped to a collection
PostPosted: Sat Sep 12, 2009 8:07 am 
Newbie

Joined: Sat Apr 11, 2009 8:19 am
Posts: 3
Hi,
Is it possible to map a native sql query to a collection set in hibernate (i am using hibernate3) ??
What i mean is ----
I have a User object mapped to a user table.
I want to have a collection of users in the user object which should be populated by a native sql query, whenever i fetch the user object from the database

How can i achieve this in hibernate??
Please help! I am new to hibernate ...


Top
 Profile  
 
 Post subject: Re: Native SQL query mapped to a collection
PostPosted: Sat Sep 12, 2009 10:23 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, you're not really going to be able to do this exactly the way you want it.

Why not just HQL? I mean, that's what the purpose of HQL is. If you're going to use Hibernate, you've got to free yourself of the SQL and move into a more object oriented domain.

If you're new to Hibernate, check out my signature links for some very simple tutorials. They'll get you up to speed and help demonstrate to you how powerful Hiberante is.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Native SQL query mapped to a collection
PostPosted: Sat Sep 12, 2009 1:44 pm 
Newbie

Joined: Sat Apr 11, 2009 8:19 am
Posts: 3
Hi Cameron,
Thanks for your quick reply ...

I can as well use HQL instead of SQL. If i use HQL, do i have to execute the query whenever i need it, or can i map it to a particular variable of a persistant class, so that it is executed automatically whenever i fetch the object from the database??

Because i want a collection to be populated automatically with the result set of a HQL query, everytime i fetch the object.

Thanks for the reference. I'll surely go through the tutorials ....


Top
 Profile  
 
 Post subject: Re: Native SQL query mapped to a collection
PostPosted: Sat Sep 12, 2009 2:15 pm 
Newbie

Joined: Sat Sep 12, 2009 2:10 pm
Posts: 2
+1 I am in an identical situation.

Without using the criteria API how can I be sure of my HQL is executed by a criteria (which will be got from a property of the entity)? This hql would be in a property of an entity as an annotation.


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.