-->
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.  [ 5 posts ] 
Author Message
 Post subject: log bind variables and SQL statement in the error log
PostPosted: Fri Oct 17, 2003 2:40 pm 
Newbie

Joined: Fri Oct 17, 2003 2:31 pm
Posts: 3
Would it be possible to have hibernate log the actual SQL statement and any bind variables used when it catches a SQL Exception?

For example, I encountered the following error while testing the my code. In this case, it would be very help if I could see the bind variables together with the SQL statement without changing the log level to something other than "error".

java.sql.SQLException: ORA-01400: cannot insert NULL into ()
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:496)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:465)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2234)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can use P6spy.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 5:35 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
enable sql logging to see exactly what sql is being attempted by putting
Code:
hibernate.show_sql=true

in hibernate.properties

or
Code:
<property name="show_sql">true</property>

in hibernate.cfg.xml

to show the bind params add
Code:
log4j.logger.net.sf.hibernate.type=debug

into your log4j properties


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 3:57 pm 
Newbie

Joined: Fri Oct 17, 2003 2:31 pm
Posts: 3
Thanks for the answers. However, they are not exactly what I ws looking for.

Using "show_sql" will print all the sql statements that have been executed. The number can be huge in a busy production system. I'm only interested in the ones that actually caused SQLExceptions. And I'd like to see the bind variables as well.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 4:39 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
Quote:
I'm only interested in the ones that actually caused SQLExceptions.

You will have to speak to your jdbc driver provider for that one! I belive Hibernate utilizes batched sql calls so the specific failure would have to be reported by your db/jdbc driver.

log4j.logger.net.sf.hibernate.type=debug

Quote:
And I'd like to see the bind variables as well.

which is exactly what:
log4j.logger.net.sf.hibernate.type=debug
does!


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