HibernateアプリケーションでP6Spyを使用してJDBCステートメントをデータベースに傍受する
質問
Hibernateコンソールアプリケーションを開発しており、この記事を参照しています http://www.mkyong.com/hibernate/how-to-display-hibernate-sql-parameter-values-solution/ 実際の値が何であるかを確認するためにP6Spyを設定するHibernateによって生成されたSQLの「(?)」の。
アプリケーションの起動中にP6SPYによって出力された情報/デバッグメッセージが表示されているので、セットアップはうまく機能するはずです。ただし、その後、P6SPYはJDBCステートメントを傍受できないようです。 Hibernate(例えば:Hibernate: insert into Module (projectName, moduleName, projectId) values (?, ?, ?)
)によって生成されたログから、JDBCステートメントが既にデータベースに送信されていることを確認できます。
私の設定は次のとおりです。
hibernate.cfg.xml
- P6Spyを使用するようにすでに指定されています
ドライバ:
<property name="hibernate.connection.driver_class">com.p6spy.engine.spy.P6SpyDriver</property>
- はすでにオンになっています
Hibernate.Show_SQLプロパティ:
<property name="hibernate.show_sql">true</property>
spy.properties
- は私の実際の使用にすでに変更されました
データベースJDBCドライバ、フィルタに設定されています
false、includecategories
何でもログに記録するように明示的に設定されています。
.module.log=com.p6spy.engine.logging.P6LogFactory realdriver=oracle.jdbc.driver.OracleDriver filter=false dateformat=yyyy.MM.dd HH:mm:ss excludecategories= includecategories=error, info, batch, debug,statement,commit,rollback,result appender=com.p6spy.engine.logging.appender.StdoutLogger
重要な設定を欠場??
- は私の実際の使用にすでに変更されました
データベースJDBCドライバ、フィルタに設定されています
false、includecategories
何でもログに記録するように明示的に設定されています。
解決 3
Finally , I give up P6Spy
as it is the old library which the latest version is back to 2003. I resort to use another similar free open source called log4jdbc
to intercept the JDBC statements , see this for more info if you are interested.
他のヒント
I've never used P6Spy, but you can get the bind variables to output to your log. Try putting this in your log4j.properties or xml file.
log4j.category.org.hibernate.type=DEBUG, CONSOLE
The usual cause for this type of problem is that the JDBC driver is loaded before the P6SpyDriver. You can get around this problem by setting deregisterdrivers=true in spy.properties.
BTW - This issue was fixed in 2.0-alpha-1.