-->
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: When show_sql is not enough
PostPosted: Tue May 10, 2005 8:37 pm 
Newbie

Joined: Tue May 10, 2005 8:26 pm
Posts: 2
Hi,

I need more info about the SQL that Hibernate generates than what is available via setting "hibernate.show_sql=true" in hibernate.properties.

Specifically, I'd like to see the values that are being bound to the queries (i.e. the values used in place of the question marks).

The following are two examples of the console output I get when setting show_sql to true:

Code:

   Hibernate: insert into domain (name, version, did) values (?, ?, ?)

   Hibernate: select this.did as did0_, this.name as name0_, this.version as version0_ from domain this where this.name=?



Any help would be most appreciated. Thanks in advance!

-Lego[/code]


Top
 Profile  
 
 Post subject: Log4j config
PostPosted: Wed May 11, 2005 6:58 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
Add these lines (or modify the logger to your logger/appender)

log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=DEBUG


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 6:25 pm 
Newbie

Joined: Tue May 10, 2005 8:26 pm
Posts: 2
Thanks, that does nicely.

-lego


Top
 Profile  
 
 Post subject: Re: Log4j config
PostPosted: Wed May 11, 2005 11:30 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
bendg25 wrote:
Add these lines (or modify the logger to your logger/appender)

log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=DEBUG


Where shall i add these lines ? I added to my log4j.properties, but it did not work?
Can you please let me know.

Thanks in advance.


Top
 Profile  
 
 Post subject: Logging
PostPosted: Thu May 12, 2005 2:06 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
If you are using Hibernate 2.x then the package name should start net.sf.hibernate instead of org.hibernate (which is the 3.x pkg structure)..

You may also have to change the word 'logger' in the lines depending on how your log4j config is setup...

If you still cannot get it working - can you post your log4j config? and Hibernate version?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 4:33 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
Im running Hibernate within an Application Server (Websphere 6) so where do I put these values /where do I put the log4j.properties file


Top
 Profile  
 
 Post subject: Hibernate logging
PostPosted: Thu May 12, 2005 5:06 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
# THIS FILE SHOULD LIVE IN webapps/yourapplication/WEB-INF/classes dir
# YOU NEED log4j.jar in your webapps/yourapplication/WEB-INF/lib dir

log4j.rootCategory=DEBUG, stdout, DR

log4j.appender.DR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DR.File=myapplication.log

# Or better still
#log4j.appender.DR.File=${myappserver.home}/logs/myapplication.log
# where myappserver.home is an exported VAR pointing to your appserver basedir

log4j.appender.DR.layout=org.apache.log4j.PatternLayout
log4j.appender.DR.layout.ConversionPattern=%d{dd-MM-yy HH:mm:ss:SSS} - {%p} %c{2} Thread [%t]; %x %m%n

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{dd-MM-yy HH:mm:ss:SSS} - {%p} %c{2} Thread [%t]; %x %m%n

# UNCOMMENT ONE OF THESE

# Hibernate 3.x
#log4j.logger.org.hibernate=ERROR
#log4j.logger.org.hibernate.SQL=DEBUG
#log4j.logger.org.hibernate.type=DEBUG

# Or Hibernate 2.x
#log4j.logger.net.sf.hibernate=ERROR
#log4j.logger.net.sf.hibernate.SQL=DEBUG
#log4j.logger.net.sf.hibernate.type=ERROR


Top
 Profile  
 
 Post subject: Logging
PostPosted: Thu May 12, 2005 5:08 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
To avoid confusion... The last post shows the contents of a file called log4j.properties (that should live in ${yourappserver_home}/webapps/yourapplication/WEB-INF/classes/log4j.properties


Top
 Profile  
 
 Post subject: Re: Logging
PostPosted: Thu May 12, 2005 5:26 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
bendg25 wrote:
To avoid confusion... The last post shows the contents of a file called log4j.properties (that should live in ${yourappserver_home}/webapps/yourapplication/WEB-INF/classes/log4j.properties


I am still confused !
I am deploying an application to Websphere as an EAR file, this consists of a WAR file for the webstuff and a JAR file which contains the session beans and all references to Hibernate.

So Im assuming the properties file should go in the JAR file, but the JAR file has no WEB-INF directory., so ive put the two files in the root of the JAR file

When I try to do something that involves talking to the database then my Websphere log file shows some Hibernate logging (as it always has done even without a log4j file), here is an extract to prove it.

Code:
[12/05/05 10:20:55:331 BST] 00000051 Environment   I   Hibernate 2.1.8
[12/05/05 10:20:55:331 BST] 00000051 Environment   I   hibernate.properties not found
[12/05/05 10:20:55:331 BST] 00000051 Environment   I   using CGLIB reflection optimizer
[12/05/05 10:20:55:347 BST] 00000051 Environment   I   using JDK 1.4 java.sql.Timestamp handling
[12/05/05 10:20:55:394 BST] 00000051 Configuration I   configuring from resource: /hibernate.cfg.xml
[12/05/05 10:20:55:394 BST] 00000051 Configuration I   Configuration resource: /hibernate.cfg.xml
[12/05/05 10:20:55:550 BST] 00000051 Configuration I   Mapping resource: com/abnamro/att/server/portfolios/domain/PtfPortfolio.hbm.xml
[12/05/05 10:20:55:675 BST] 00000051 Binder        I   Mapping class: com.abnamro.att.server.portfolios.domain.PtfPortfolio -> PTF_PORTFOLIO
[12/05/05 10:20:55:847 BST] 00000051 Configuration I   Mapping resource: com/abnamro/att/server/portfolios/domain/StlStockline.hbm.xml
[12/05/05 10:20:55:909 BST] 00000051 Binder        I   Mapping class: com.abnamro.att.server.portfolios.domain.StlStockline -> STL_STOCKLINE
[12/05/05 10:20:55:941 BST] 00000051 Configuration I   Mapping resource: com/abnamro/att/server/portfolios/domain/PttPortfolioType.hbm.xml
[12/05/05 10:20:55:956 BST] 00000051 Binder        I   Mapping class: com.abnamro.att.server.portfolios.domain.PortfolioType -> PTT_PORTFOLIO_TYPE
[12/05/05 10:20:55:956 BST] 00000051 Configuration I   Mapping resource: com/abnamro/att/server/portfolios/domain/TrdTrade.hbm.xml
[12/05/05 10:20:55:972 BST] 00000051 Binder        I   Mapping class: com.abnamro.att.server.portfolios.domain.TrdTrade -> TRD_TRADE
[12/05/05 10:20:56:019 BST] 00000051 Configuration I   Mapping resource: com/abnamro/att/server/security/domain/UsrUser.hbm.xml
[12/05/05 10:20:56:034 BST] 00000051 Binder        I   Mapping class: com.abnamro.att.server.security.domain.User -> USR_USER
[12/05/05 10:20:56:034 BST] 00000051 Configuration I   Configured SessionFactory: null
[12/05/05 10:20:56:050 BST] 00000051 Configuration I   processing one-to-many association mappings
[12/05/05 10:20:56:050 BST] 00000051 Configuration I   processing one-to-one association property references
[12/05/05 10:20:56:066 BST] 00000051 Configuration I   processing foreign key constraints
[12/05/05 10:20:56:128 BST] 00000051 Dialect       I   Using dialect: net.sf.hibernate.dialect.OracleDialect
[12/05/05 10:20:56:159 BST] 00000051 SettingsFacto I   Use outer join fetching: true
[12/05/05 10:20:56:175 BST] 00000051 NamingHelper  I   JNDI InitialContext properties:{}


but I cant get it to log at debug level, data retrievals only show the basic sql output
e.g
Code:
[12/05/05 10:21:49:773 BST] 00000052 SystemOut     O Hibernate: select this.PTF_PK as PTF_PK2_, this.LOCK_NUM as LOCK_NUM2_, this.NAME as NAME2_, this.DESCRIPTION as DESCRIPT4_2_, this.VOLUME as VOLUME2_, this.CLASS as CLASS2_, this.CREATION_DT as CREATION7_2_, this.PTT_FK as PTT_FK2_, this.USR_FK as USR_FK2_, portfoliot1_.PTT_PK as PTT_PK0_, portfoliot1_.NAME as NAME0_, user2_.USR_PK as USR_PK1_, user2_.DELETED as DELETED1_, user2_.NAME as NAME1_, user2_.DESCRIPTION as DESCRIPT4_1_, user2_.PASSWORD as PASSWORD1_ from PTF_PORTFOLIO this, PTT_PORTFOLIO_TYPE portfoliot1_, USR_USER user2_ where 1=1 and this.PTT_FK=portfoliot1_.PTT_PK(+) and this.USR_FK=user2_.USR_PK(+)


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.