精通 Grails: 在企业中使用 Grails
查看 Hibernate DEBUG 输出
回到先前的假设,您正在调试一个实时 Grails 应用程序,但还没有找到您需要的东西。将根 MBean 的优先级属性设置回 ERROR 来减少干扰。
可能问题就出在 Hibernate。再回过头看看 Config.groovy,您会发现 org.hibernate 包的登录输出被设置为 off。不要改变整个应用程序的输出级别,而是集中于特定的包,这样可能会获得更多的信息。
在 JConsole 中,单击默认 MBean。除了更改属性值以外,您还可以调用 MBean 上的方法。单击 Operations 选项卡。为名称参数输入 org.hibernate 并单击 addLoggerMBean 按钮。您应该会看到一个新的 MBean 出现在左边的树中。
单击新的 org.hibernate MBean 并将优先级属性更改为 DEBUG,如图 9 所示:
图 9. 更改 org.hibernate MBean 上的优先级

现在返回到 Web 浏览器,单击主链接,并再次单击 AirportMappingController 。应该会看到一大串 DEBUG 日志语句,如清单 10 所示:
清单 10. Hibernate log4j 输出
[DEBUG] 10:05:52 (AbstractBatcher.java:logOpenPreparedStatement:366)
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[DEBUG] 10:05:52 (ConnectionManager.java:openConnection:421)
opening JDBC connection
[DEBUG] 10:05:52 (AbstractBatcher.java:log:401)
select this_.airport_id as airport1_0_0_, this_.locid as locid0_0_,
this_.latitude as latitude0_0_, this_.longitude as longitude0_0_,
this_.airport_name as airport5_0_0_, this_.state as state0_0_
from usgs_airports this_ limit ?
[DEBUG] 10:05:52 (AbstractBatcher.java:logOpenResults:382)
about to open ResultSet (open ResultSets: 0, globally: 0)
[DEBUG] 10:05:52 (Loader.java:getRow:1173)
result row: EntityKey[AirportMapping#1]
[DEBUG] 10:05:52 (Loader.java:getRow:1173)
result row: EntityKey[AirportMapping#2]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[DEBUG] 10:05:52 (ConnectionManager.java:openConnection:421)
opening JDBC connection
[DEBUG] 10:05:52 (AbstractBatcher.java:log:401)
select this_.airport_id as airport1_0_0_, this_.locid as locid0_0_,
this_.latitude as latitude0_0_, this_.longitude as longitude0_0_,
this_.airport_name as airport5_0_0_, this_.state as state0_0_
from usgs_airports this_ limit ?
[DEBUG] 10:05:52 (AbstractBatcher.java:logOpenResults:382)
about to open ResultSet (open ResultSets: 0, globally: 0)
[DEBUG] 10:05:52 (Loader.java:getRow:1173)
result row: EntityKey[AirportMapping#1]
[DEBUG] 10:05:52 (Loader.java:getRow:1173)
result row: EntityKey[AirportMapping#2]
花一点时间查看 Hibernate DEBUG 输出。您详细了解到何时从数据库挑选数据,并转换为一个由 bean 组成的 ArrayList。
0
相关文章