-->
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: how to see the actual SQL Query?
PostPosted: Tue Nov 28, 2006 4:30 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi,

How can I see the actual SQL query that are generated by NHibernate?

And how can I cuztomize those query, if possible. Is it by changing the HQL or Criteria order?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:41 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 12:13 pm
Posts: 44
Location: Denver, CO
The easiest way to watch the actual SQL queries generated and troubleshoot, accordingly, is with log4net. Download log4net, add a reference to it within your project and then do the following...

Add the following to your app/web.config:

Code:
<?xml version="1.0"?>
<configuration>
   <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
   </configSections>
   <!-- If you want to turn it off completely for all loggers, include 'threshold="OFF"' in the log4net tag immediately following this -->
   <log4net>
      <appender name="LogAllToFile" type="log4net.Appender.FileAppender">
         <file value="whatever.log"/>
         <appendToFile value="false"/>
         <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d [%t] %-5l - %m%n%n"/>
         </layout>
      </appender>
      <root>
         <priority value="ALL"/>
         <!-- ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF-->
         <appender-ref ref="LogAllToFile"/>
      </root>
   </log4net>
</configuration>


And then in the Application_Start method of Global.asax...

Code:
// Initialize log4net
XmlConfigurator.Configure();


With this in place, whatever.log will be populated with all the actual SQL queries, along with a bunch of other stuff.

Alternatively, you can also mess around with Ayende@Rahien's NHibernate Query Analyzer found at http://www.ayende.com/projects/nhiberna ... lyzer.aspx

Billy


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.