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: auto-generating SQL, can NHibernate help?
PostPosted: Wed Aug 13, 2008 9:39 am 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
NHibernate 1.2.1
.Net 3.5



We've got a small app that requires some flexibilty in it's data and we're looking at autogenerating some SQL. Is there any way to piggy back off of NHibernate for this? The queries will all be relatively simple except for the requirement that they support sub-queries.

What I'd like to do is create a query using ICriteria or IQuery (preferrably ICriteria), have NHibernate auto-generate the SQL, and we pluck it out and store it elsewhere (the queries themselves will be write rarely, read mostly).

Or, if NHibernate exposes hooks for it's internal SQL generation mechanism, that'd be even better.


1. Is it possible to do sub-queries with ICriteria, and
2. How would I get at the SQL generated by NHibernate without having NHibernate actually query the database?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 10:50 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
1. Is it possible to do sub-queries with ICriteria, and


Yes, with detached criterias:

Code:
crit.Add(Subqueries.Exists(detachedCriteria))

[url]
http://www.hibernate.org/hib_docs/nhibe ... hedqueries[/url]

Quote:
2. How would I get at the SQL generated by NHibernate without having NHibernate actually query the database?


I don't think you can get the actual statements. But you can try that question on the nhusers group at google (search that group before).

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 1:04 pm 
Newbie

Joined: Thu Jun 28, 2007 5:02 pm
Posts: 12
Where x is an open ISession object...

string aSQLString = x.GetSessionImplementation().GetQueries(anHQLQueryString, false)[0].SQLString

GetQueries returns an array. The example above just shows the first raw SQL statement needed to perform the HQL query you've provided. (Depending on the HQL complexity, there might be more than one query performed by the translator)


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.