-->
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: How to check last executed SQL statements
PostPosted: Mon Aug 22, 2005 12:40 pm 
Beginner
Beginner

Joined: Tue Aug 09, 2005 9:43 am
Posts: 30
Location: Lisbon, Portugal
I'm having trouble with a one-to-many association (actually my first... :wink: ). I'm not desperate enough to bother you all with it *yet*, but I'm having some trouble debugging my mistakes in using NHibernate and started feeling frustrated - having abandoned my own frugal Persistence Layer implementation, I really miss one feature it had for debugging purposes: the ability to check the last n executed SQL statements (n was configurable). It was a really nice way to detect odd behavior or just build trust on what's happening. I don't know if log4net can be used for this. I'm also having trouble with it since I'm using NUnit and TestDriven.NET to test an Assembly directly and can't get it to work (no App.config or web.config there - actually I have an App.config in the Assembly project but doesn't seem to help at all - I do have it working in a web application though but that's not the way I intend to test my app).

So the question really is: can I check the last few SQL statements that NHibernate executed, even if there were no SQL errors reported?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 4:20 pm 
Check out NHibernate.Log.txt. It should contain all SQL submitted to the database.


Top
  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 4:50 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 9:43 am
Posts: 30
Location: Lisbon, Portugal
Where would that file be? I have searched for it in both NHibernate's directory and my project's. I have done nothing to produce that file... who's writing it and why - a configuration option maybe?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 4:56 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 9:43 am
Posts: 30
Location: Lisbon, Portugal
Ooooops! Just checking the latest release *hot* *hot* and read this:

- Implemented hibernate.show_sql feature, logging all SQL executed using NHibernate.SQL logger.

This will probably help... I'm going to check it now.
Many thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 8:45 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If you configure log4net and enable debugging, all this stuff will be written in a file (its default name is "log.txt")

Read: Configuring log4net Logging

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 4:50 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 9:43 am
Posts: 30
Location: Lisbon, Portugal
Yeah, that's what I thought. This is my web app's web.config (I don't usually test using the GUI but I have a similar App.config to go with the test .dll). I do get an empty log.txt file in the web site's root. :o

Any clues?


Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
      <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
   </configSections>
   <nhibernate>
      <add
         key="hibernate.show_sql"
         value="true"
      />      
      <!-- Put your nhibernate configuration here --></nhibernate>
   <!-- This section contains the log4net configuration settings -->
   <log4net debug="true">
      <!-- Define some output appenders -->
      <appender name="trace" type="log4net.Appender.TraceAppender, log4net">
         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
         <param name="File" value="log.txt" />
         <param name="AppendToFile" value="false" />
         <param name="RollingStyle" value="Date" />
         <param name="DatePattern" value="yyyy.MM.dd" />
         <param name="StaticLogFileName" value="true" />
         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <!-- Setup the root category, add the appenders and set the default priority -->
      <root>
         <priority value="ERROR" />
         <appender-ref ref="rollingFile" />
      </root>
      <logger name="NHibernate.Impl.BatcherImpl">
         <level value="ERROR" />
      </logger>
   </log4net>
   <system.web>
      <!--  DYNAMIC DEBUG COMPILATION
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.
    -->
      <compilation defaultLanguage="vb" debug="true" />
      <!--  CUSTOM ERROR MESSAGES
          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
          Add <error> tags for each of the errors you want to handle.

          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running
           on the local Web server. This setting is recommended for security purposes, so
           that you do not display application detail information to remote clients.
    -->
      <customErrors mode="RemoteOnly" />
      <!--  AUTHENTICATION
          This section sets the authentication policies of the application. Possible modes are "Windows",
          "Forms", "Passport" and "None"

          "None" No authentication is performed.
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
           its settings for the application. Anonymous access must be disabled in IIS.
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    -->
      <authentication mode="Windows" />
      
        <!--
        identity Attributes:
          impersonate="[true|false]" - Impersonate Windows User
            userName="Windows user account to impersonate" | empty string implies impersonate the LOGON user specified by IIS 
            password="password of above specified account" | empty string
        -->
        <identity impersonate="true" userName="" password=""/>   
      
      <!--  AUTHORIZATION
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
          (unauthenticated) users.
    -->
      <authorization>
         <allow users="*" /> <!-- Allow all users -->
         <!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
      </authorization>
      <!--  APPLICATION-LEVEL TRACE LOGGING
          Application-level tracing enables trace log output for every page within an application.
          Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
          trace information will be displayed at the bottom of each page.  Otherwise, you can view the
          application trace log by browsing the "trace.axd" page from your web application
          root.
    -->
      <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
      <!--  SESSION STATE SETTINGS
          By default ASP.NET uses cookies to identify which requests belong to a particular session.
          If cookies are not available, a session can be tracked by adding a session identifier to the URL.
          To disable cookies, set sessionState cookieless="true".
    -->
      <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
         cookieless="false" timeout="20" />
      <!--  GLOBALIZATION
          This section sets the globalization settings of the application.
    -->
      <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
   </system.web>
</configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 8:31 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Yep - change the logging priority in the following section in your log4net configuration from ERROR to another value such as DEBUG or INFO.

Code:
       <logger name="NHibernate.Impl.BatcherImpl">
         <level value="ERROR" />
      </logger>


DEBUG will display reams and reams of data, so INFO might be a better first choice.

ERROR will only log errors, so if you're not getting any then they won't be written to your file! :)

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 6:46 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 9:43 am
Posts: 30
Location: Lisbon, Portugal
HA! Perfect! :D
I'm even greener to log4net than to NHibernate...! It would take me ages to figure that out.

Many thanks!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 10:08 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
No problem - I had the same problem. :)

Cheers,

Symon.


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.