-->
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: Question about executing arbitrary native SQL
PostPosted: Thu Sep 16, 2004 10:30 pm 
Newbie

Joined: Thu Sep 16, 2004 8:56 pm
Posts: 3
Hibernate version: 2.1.6

I have a Hibernate persisted object, Recipe, in a table "recipe". I need to utilize a native SQL statement like the following:

Code:
select substring(lower(name) from 1 for ?) as section, count(*) as cnt from recipe group by section


but obviously this is not intended to return recipe objects... as a Recipe object does not have either "section" or "cnt" properties.

My question is, in general what is the appropriate way to accomplish this type of arbitrary native SQL in Hibernate? There are some cases where I want to execute arbitrary queries that return result sets that don't map to Hibernate-persisted object properties.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use session.connection() and do it the plain old JDBC way


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 11:31 am 
Newbie

Joined: Tue Aug 24, 2004 6:47 am
Posts: 3
It works!

Example:
Query sqlQuery = session.createQuery("select substr(quiz.a_StartDate,1,2) from E_Quiz quiz");


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.