-->
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.  [ 2 posts ] 
Author Message
 Post subject: StoredProcs and adhoc sql queries
PostPosted: Sat Dec 08, 2007 9:48 am 
Newbie

Joined: Sat Dec 08, 2007 9:22 am
Posts: 10
Hi All,

First off I am extreemly new to NHibernate so if I ask anything stupid I appologise in advance.

My question is this, I previously worked on a site that used google maps api to search a list of events by distance from a geocoded postcode. In this project I had a SProc that took lat, long params and returned a list of venue id's of which my activities were mapped against and thus could be found via a join. As im playing im trying to recrete this project with NHibernate and Im stuck with a few point.

Firstly, can I only use NHibernate to map objects or is it possible to perform adhoc queries that simple return a data set of some type? In this case I simply want a list of int returning.

Secondly, can I still use my SProc with NHibernate? Without going into too much info there's quite a lot of db calls happen in this SProc to return the data I want. Moving this to the application side would mean either alot of round trips to the db or a single trip to retrieve a massive data set which could be queried in mem. I dont really want to do either and would rather this type of processing stayed at the db layer.

Thirdly, if i can get NHibernate to use my SProc to return a list of venueIDs could I then use this with a query to join on the activities i.e.

//Normal SQL
SELECT A.* FROM [Activities] as A
INNER JOIN [ActivitiesToVenues] as AtoV on A.ID = AtoV.ActivityID INNER JOIN [Venues] as V on AtoV.VenueID = V.ID
WHERE VenueID IN {results of my SProc}

I actually did this in the same SProc before, but then I knew exactly what I wanted to return to build up my object.

As it happens my activity object has a few collections bound to it i.e. venues, categories, facilities. All of which were returned as from the same SProc and the Activity object and its collections were all built up in one i.e. no lazy loading.

Now i'd like NHibernate to build up my activity objects, meaning an extra db round trip or so, but I still need to feed a query with the venue id's from the SProc.

I guess im asking alot of different questions and I am going to continue to look through the docs, but if any of this made sense fell free to point me in the right direction.

Cheers, Chris.


Top
 Profile  
 
 Post subject: Re: StoredProcs and adhoc sql queries
PostPosted: Sat Dec 08, 2007 3:28 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Chiefos wrote:
Firstly, can I only use NHibernate to map objects or is it possible to perform adhoc queries that simple return a data set of some type? In this case I simply want a list of int returning.


Yes, you can use NHibernate for ad-hoc queries that return things other than your objects. Just use the SELECT clause in your HQL such as "SELECT v.VenueID FROM Venue v WHERE ..."

Chiefos wrote:
Secondly, can I still use my SProc with NHibernate? Without going into too much info there's quite a lot of db calls happen in this SProc to return the data I want. Moving this to the application side would mean either alot of round trips to the db or a single trip to retrieve a massive data set which could be queried in mem. I dont really want to do either and would rather this type of processing stayed at the db layer.


Yes, you can do this as well. See the following link from the NHibernate documentation for more information: http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#sp_query

You could also read a blog post from Oren Eini (Ayende @ Rahien): http://www.ayende.com/Blog/archive/7263.aspx

Chiefos wrote:
Thirdly, if i can get NHibernate to use my SProc to return a list of venueIDs could I then use this with a query to join on the activities i.e.

//Normal SQL
SELECT A.* FROM [Activities] as A
INNER JOIN [ActivitiesToVenues] as AtoV on A.ID = AtoV.ActivityID INNER JOIN [Venues] as V on AtoV.VenueID = V.ID
WHERE VenueID IN {results of my SProc}


Yes you can do this too, but it will require a second round trip. First run the procedure to return the list of VenueID values and then run a new NHibernate query providing just the list of the VenueIDs.


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