-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to extract SQL generated by Hibernate
PostPosted: Wed Mar 28, 2007 5:21 pm 
Newbie

Joined: Wed Mar 28, 2007 5:13 pm
Posts: 2
Hi Hibernate Gurus,
I am a newbie with Hibernate and I have this question for you guys.
Is it possible to extract the SQL that Hibernate generates even before executing the query? If yes, how?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 5:26 pm 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
you may use several options, i believe the manual mentions them.

1. set up the hibernate.show_sql option to true, for exmaple in hibernate.cfg.xml

Code:
    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.use_sql_comments">true</property>
    <property name="hibernate.query.substitutions">true 1, false 0</property>


(There are som more properties you may find helpfull.)

2. Use the log level DEBUG for org.hibernate.SQL log4j logger, sample log4j.properties to print to console:

Code:
log4j.rootLogger = DEBUG, console

log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-4r [%t] %-5p (%c{1}) %l - %m%n

log4j.logger.org.hibernate.SQL = DEBUG, console
log4j.additivity.org.hibernate.SQL = false


regards, martin


Top
 Profile  
 
 Post subject: Re: How to extract SQL generated by Hibernate
PostPosted: Wed Mar 28, 2007 5:38 pm 
Newbie

Joined: Wed Mar 28, 2007 5:13 pm
Posts: 2
Martin, Thanks for the reply. However, I have already looked at these options and implemented it. This will log SQL only after some action on the application. I need to grab the SQL even without an action and move it from hibernate to elsewhere. Any help is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 5:55 pm 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
sorry, i dont know if it is possible.

probably you are asking because you will use hibernate as "sql generator" and execute the generated sql by other means -- if so (just guessing) -- i have only partial solution for Python :-) -- i know only of Python to be able to incorporate hiberante (using Jython). But in case of Python, onewould probably use SQLAlchemy or SQLObject,

so, no further ideas from me :-(


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