-->
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.  [ 11 posts ] 
Author Message
 Post subject: View generated SQL?
PostPosted: Fri Feb 10, 2006 1:12 pm 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
Is there a way to view the SQL generated by NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 4:17 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
Try putting this in your config file

Code:
  </log4net>
    <appender name="NHFile" type="log4net.Appender.RollingFileAppender,log4net" >
      <param name="File" value="NHibLog.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
       <maxSizeRollBackups value="10" />
       <maximumFileSize value="100KB" />
      <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] - %m%n" />
      </layout>
    </appender>

    <root>
       <level value="WARN"/>
       <appender-ref ref="File" />
    </root>

    <logger name="NHibernate" additivity="false">
      <level value="DEBUG" />
      <appender-ref ref="NHFile"/>
    </logger>
  </log4net>


You should get a log file named NHibLog.txt in the same folder as the config file.


Top
 Profile  
 
 Post subject: show-sql
PostPosted: Sun Feb 12, 2006 11:58 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Or you can do this by
Code:
<nhibernate>
      <add key="hibernate.show_sql" value="true" />
</nhibernate>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 6:06 am 
Newbie

Joined: Wed Dec 21, 2005 6:17 am
Posts: 10
Something important! ;)
To be XML-conform the first line has to be this way:
Code:
<log4net>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 7:07 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
If you are using MySQL, you can use the log file.

Add to your my.cnf, in the [mysqld] section, the following:

Code:
log=C:\mysql\data\mysql.log


This will log Inserts, Updates, Deletes and Selectes.

Bye


Top
 Profile  
 
 Post subject: Re: show-sql
PostPosted: Mon Feb 13, 2006 7:08 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
samujob wrote:
Or you can do this by
Code:
<nhibernate>
      <add key="hibernate.show_sql" value="true" />
</nhibernate>


Samujob.. using this way, where the log will be generated?

Thanks


Top
 Profile  
 
 Post subject: Console
PostPosted: Mon Feb 13, 2006 7:22 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
It will always display it in the Console. Following is the code

Code:
private void Log(String sql){
         logSql.Debug(sql);
         if ( factory.IsShowSqlEnabled ) {
            Console.Out.WriteLine("NHibernate :" + sql);
         }
      }


Top
 Profile  
 
 Post subject: Re: Console
PostPosted: Mon Feb 13, 2006 8:34 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
samujob wrote:
It will always display it in the Console. Following is the code

Code:
private void Log(String sql){
         logSql.Debug(sql);
         if ( factory.IsShowSqlEnabled ) {
            Console.Out.WriteLine("NHibernate :" + sql);
         }
      }


I didn't understand... where should I put this code?

Could you explain?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 9:56 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
he's quoting the sourcecode of hibernate. You don't have to do anything, it just means that with the 'show_sql' in your config file, the output will _always_ be sent to the console window, no way to change anything.

Did that help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 11:18 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
TheShark wrote:
he's quoting the sourcecode of hibernate. You don't have to do anything, it just means that with the 'show_sql' in your config file, the output will _always_ be sent to the console window, no way to change anything.

Did that help?


HUmmmmmmmm! :)

Thanks ;)

I have just one more question (simple questin..): how can I enable the Console for web apps?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 3:42 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
If you are using NH in a web service, I suggest you try the method I proposed above, i.e. logging to a file via log4net. I am using NH in a web service and do my logging this way.

SOL-Invictus wrote:
Something important! ;)
To be XML-conform the first line has to be this way:
Code:
<log4net>


Thanks SOL-Invictus. I was missing the tag when I copied from my config, and cut/paste the closing tag but forgot to change it.


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