启用休眠日志记录
我正在尝试创建休眠语句的日志。我使用JPA执行我的sql语句,其中Hibernate 2.0是持久性提供程序(我的应用程序服务器是JBoss AS 6.0)。我使用 EJB 3.0 提供的 EntityManager 接口调用我的 CRUD 方法。我阅读了许多关于启用hinernate日志记录的帖子,但实际上我看不到任何日志:-(我创建了一个 log4j.properties 文件,并将其放在 Netbeans 项目的根文件夹中。我还将log4j库放在项目的类路径中。我的 log4j.properties 如下所示:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n
log4j.rootLogger=debug, stdout
log4j.logger.org.hibernate=info
### log just the SQL
log4j.logger.org.hibernate.SQL=debug
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=info
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
### log cache activity ###
log4j.logger.org.hibernate.cache=info
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
为什么我看不到日志信息?我希望在sql where子句或插入语句中看到值(实际上我只看到一些'?')提前致谢。
为了清楚起见,我把项目的文件夹结构放在下面:
MyProject
¦ build.xml
¦ log4j.properties
¦
+---build
¦ ¦ capitolo2-ejb.jar
¦ ¦ capitolo2-war.war
¦ ¦ JBoss4.dpf
¦ ¦
¦ +---lib
¦ ¦ log4j-1.2.15.jar
¦ ¦ slf4j-api.jar
¦ ¦ slf4j-jboss-logmanager.jar
¦ ¦
¦ +---META-INF
¦ chapter2-hornetq-jms.xml
¦ jboss-app.xml
¦ log4j.properties
¦ MANIFEST.MF
¦
+---capitolo2-ejb
¦ ¦ build.xml
¦ ¦
¦ ¦
¦ +---build
¦ ¦ +---classes
¦ ¦ ¦ ¦ .netbeans_automatic_build
¦ ¦ ¦ ¦ .netbeans_update_resources
¦ ¦ ¦ ¦
¦ ¦ ¦ +---ejb
¦ ¦ ¦ ¦ +---com
¦ ¦ ¦ ¦ +---ejb3inaction
¦ ¦ ¦ ¦ +---actionbazaar
¦ ¦ ¦ ¦ +---buslogic
¦ ¦ ¦ ¦ ¦ BillingException.class
¦ ¦ ¦ ¦ ¦ OrderBillingMDB.class
¦ ¦ ¦ ¦ ¦ PlaceBid.class
¦ ¦ ¦ ¦ ¦ PlaceBidBean.class
¦ ¦ ¦ ¦ ¦ PlaceOrder.class
¦ ¦ ¦ ¦ ¦ PlaceOrderBean.class
¦ ¦ ¦ ¦ ¦
¦ ¦ ¦ ¦ +---persistence
¦ ¦ ¦ ¦ Bid.class
¦ ¦ ¦ ¦ BillingInfo.class
¦ ¦ ¦ ¦ Order.class
¦ ¦ ¦ ¦ OrderStatus.class
¦ ¦ ¦ ¦ ShippingInfo.class
¦ ¦ ¦ ¦
¦ ¦ ¦ +---META-INF
¦ ¦ ¦ beans.xml
¦ ¦ ¦ jboss.xml
¦ ¦ ¦ MANIFEST.MF
¦ ¦ ¦ persistence.xml
¦ ¦ ¦
¦ ¦ +---empty
¦ ¦ +---generated-sources
¦ ¦ +---ap-source-output
¦ +---dist
¦ ¦ capitolo2-ejb.jar
¦ ¦
¦ +---lib
¦ ¦ log4j-1.2.15.jar
¦ ¦
¦ +---nbproject
¦ ¦ ¦ ant-deploy.xml
¦ ¦ ¦ build-impl.xml
¦ ¦ ¦ genfiles.properties
¦ ¦ ¦ project.properties
¦ ¦ ¦ project.xml
¦ ¦ ¦
¦ ¦ +---private
¦ ¦ private.properties
¦ ¦ private.xml
¦ ¦
¦ +---setup
¦ ¦ jboss-ds.xml
¦ ¦
¦ +---src
¦ +---conf
¦ ¦ beans.xml
¦ ¦ jboss.xml
¦ ¦ MANIFEST.MF
¦ ¦ persistence.xml
¦ ¦
¦ +---java
¦ +---ejb
¦ +---com
¦ +---ejb3inaction
¦ +---actionbazaar
¦ +---buslogic
¦ ¦ BillingException.java
¦ ¦ OrderBillingMDB.java
¦ ¦ PlaceBid.java
¦ ¦ PlaceBidBean.java
¦ ¦ PlaceOrder.java
¦ ¦ PlaceOrderBean.java
¦ ¦
¦ +---persistence
¦ Bid.java
¦ BillingInfo.java
¦ Order.java
¦ OrderStatus.java
¦ ShippingInfo.java
¦
+---capitolo2-war
¦ ¦ build.xml
¦ ¦
¦ +---build
¦ ¦ +---empty
¦ ¦ +---generated-sources
¦ ¦ ¦ +---ap-source-output
¦ ¦ +---lib
¦ ¦ ¦ log4j-1.2.15.jar
¦ ¦ ¦ slf4j-api.jar
¦ ¦ ¦ slf4j-jboss-logmanager.jar
¦ ¦ ¦
¦ ¦ +---web
¦ ¦ ¦ index.jsp
¦ ¦ ¦
¦ ¦ +---META-INF
¦ ¦ ¦ MANIFEST.MF
¦ ¦ ¦
¦ ¦ +---WEB-INF
¦ ¦ ¦ beans.xml
¦ ¦ ¦ jboss-web.xml
¦ ¦ ¦
¦ ¦ +---classes
¦ ¦ ¦ .netbeans_automatic_build
¦ ¦ ¦ .netbeans_update_resources
¦ ¦ ¦
¦ ¦ +---it
¦ ¦ +---myservlets
¦ ¦ PlaceBidServlet.class
¦ ¦ PlaceOrderServlet.class
¦ ¦
¦ +---dist
¦ ¦ capitolo2-war.war
¦ ¦
¦ +---nbproject
¦ ¦ ¦ ant-deploy.xml
¦ ¦ ¦ build-impl.xml
¦ ¦ ¦ genfiles.properties
¦ ¦ ¦ project.properties
¦ ¦ ¦ project.xml
¦ ¦ ¦
¦ ¦ +---private
¦ ¦ private.properties
¦ ¦ private.xml
¦ ¦
¦ +---setup
¦ ¦ jboss-ds.xml
¦ ¦
¦ +---src
¦ ¦ +---conf
¦ ¦ ¦ MANIFEST.MF
¦ ¦ ¦
¦ ¦ +---java
¦ ¦ +---it
¦ ¦ +---myservlets
¦ ¦ PlaceBidServlet.java
¦ ¦ PlaceOrderServlet.java
¦ ¦
¦ +---web
¦ ¦ index.jsp
¦ ¦
¦ +---WEB-INF
¦ beans.xml
¦ jboss-web.xml
¦
+---dist
¦ capitolo2.ear
¦
+---nbproject
¦ ¦ ant-deploy.xml
¦ ¦ build-impl.xml
¦ ¦ genfiles.properties
¦ ¦ project.properties
¦ ¦ project.xml
¦ ¦
¦ +---private
¦ private.properties
¦
+---setup
¦ jboss-ds.xml
¦ jboss4-netbeans-destinations-service.xml
¦ log4j.properties
¦
+---src
+---conf
chapter2-hornetq-jms.xml
jboss-app.xml
log4j.properties
MANIFEST.MF