-->
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.  [ 9 posts ] 
Author Message
 Post subject: Accessing generated SQL statements
PostPosted: Wed Jun 07, 2006 12:21 pm 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
Hi,
Is there any way I can gain access to the SQL NHibernate generates? No, no modifications intended :)
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 12:24 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
In your config file simply set the show_sql property to true


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 12:29 pm 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
grennis wrote:
In your config file simply set the show_sql property to true


My bad :) Somewhat incorrect question.
I actually need to be able to save the SQL it generates to the database (for the sake of logging, debugging and stuff like that). I'm not sure if writing a custom Appender for log4net will help, since I need to write lots of other stuff along with the SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 12:33 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
The log4net output doesn't show the parameter values anyway


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 2:22 pm 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
grennis wrote:
The log4net output doesn't show the parameter values anyway


It does :)
2006-06-07 22:05:17,804 [1624] DEBUG NHibernate.SQL [(null)] <(null)> - SELECT permission0_.ID as ID0_, permission0_.Description as Descript4_0_, permission0_.Name as Name0_, permission0_.Guid as Guid0_ FROM Permission permission0_ WHERE permission0_.ID=@p0
2006-06-07 22:05:17,804 [1624] DEBUG NHibernate.SQL [(null)] <(null)> - @p0 = '1'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 8:41 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
That's weird, mine only shows the statement. What the ...?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 10:10 am 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
All right, I found a couple of ways to get hold of SQL :)
First is to write custom Entity Persister (IEntityPersister) and retrieve SQL from IDbCommand in Dehydrate().
Second is to write a custom Batcher (IBatcher), since all operations are performed via Batcher. But there's one thing -- batcher can only be substituted at runtime using reflection (ISession has a field named batcher).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 12:33 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Hmmm, we'll have to try implementing IEntityPersister. Still, that seems like a hassle just to get the SQL. We "cheated" by creating a NHibernate.Hql.QueryTranslator for the given HQL text, calling queryTranslator.Compile(), and then using reflection to get at its protected SqlString property.

Request: the SQL text should be exposed as public and readonly, either throuh a separate property for .NET 1.1 or with a public getter and protected setter in .NET 2.0.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 11:46 am 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
Nels_P_Olsen wrote:
Hmmm, we'll have to try implementing IEntityPersister. Still, that seems like a hassle just to get the SQL. We "cheated" by creating a NHibernate.Hql.QueryTranslator for the given HQL text, calling queryTranslator.Compile(), and then using reflection to get at its protected SqlString property.

Request: the SQL text should be exposed as public and readonly, either throuh a separate property for .NET 1.1 or with a public getter and protected setter in .NET 2.0.


SQL text alone is not enough, unless it will explicitly contain parameters' values.


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