-->
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.  [ 1 post ] 
Author Message
 Post subject: Returning Hibernate Entities
PostPosted: Thu Jul 09, 2009 6:04 pm 
Newbie

Joined: Thu Jul 09, 2009 3:54 pm
Posts: 1
Hi, I'm going through an application and replacing the raw SQL queries with Hibernate syntax. As a first step, I'm working on having the SQL return Hibernate Entities. For example, I'm replacing this:

SELECT * FROM Office

with this:

NHibernateSession.CreateSQLQuery("SELECT * FROM Office").AddEntity(GetType(Office)).list()

and then using the returned Office objects. However, I can't figure out how to get entities back from more complicated SQL queries. I've run into the below SQL statement. It selects all from Office, but also returns a derived column called "Distance" that is calculated using a SQL function called "getDistance".

SELECT *, db.getDistance(:lat, :lng, Latitude, Longitude) AS Distance FROM Office

Does anyone know how I could have entities return from this? If I use this:

NHibernateSession.CreateSQLQuery(sql).AddEntity(GetType(Office)).list()

it compiles and runs, but it seems to drop the Distance field (as expected). I've tried using .AddScalar() for the "Distance" column, but I can't figure out the structure of the returned List. Does anyone have any ideas? Thanks.


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

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.