如何从Hibernate获取更多的调试消息? [英] How do I get more debug messages from Hibernate?

查看:158
本文介绍了如何从Hibernate获取更多的调试消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管在 hibernate.cfg.xml 文件中设置了一些属性,我仍然无法从Hibernate获得任何更多的控制台输出(帮助调试)。例如,添加行< property name =show_sql> true< / property> 实际上没有在控制台中显示SQL语句。 >

我也尝试着使用 log4j.properties 文件的内容 - 像设置 log4j.logger.org.hibernate = debug - 没有运气。我缺少什么?






编辑: hibernate-service.xml文件的内容是

 < server> 
< mbean code =org.jboss.hibernate.jmx.Hibernate
name =jboss.har:service = Hibernate_SMS>
< attribute name =DatasourceName> java:/ SMS_DS< / attribute>
< attribute name =Dialect> org.hibernate.dialect.HSQLDialect< / attribute>
< attribute name =SessionFactoryName> java:/ hibernate / SessionFactory< / attribute>
< attribute name =CacheProviderClass> org.hibernate.cache.HashtableCacheProvider< / attribute>
< attribute name =ShowSqlEnabled> true< / attribute>
< / mbean>
< / server>

尽管如此,我不是100%肯定的。该XML文件位于处理我的数据库东西的Eclipse项目中,但似乎不在JBoss部署目录中。






编辑2:这绝对被部署为HAR。也就是说,我确信我需要 hibernate.cfg.xml - 我记得在将该映射文档作为该文件中的条目省略时,会有问题。我认为HAR是使用ant生成的 - 在build.xml文件中有一个目标:

 < target name = hardepends =preparedescription =构建Hibernate HAR文件> 
< mkdir dir =$ {class.root}/>
< mkdir dir =$ {distribution.dir}/>

< jar destfile =$ {distribution.dir} / $ {har.name}>
<! - 包含hbm.xml文件 - >
< fileset dir =$ {class.root}>
< include name =** / *。hbm.xml/>
< include name =com / / sms / data / dto / *。class/>
< include name =com / [refacted] / sms / data / dto / base / *。class/>
< / fileset>

<! - include jboss-service.xml - >
< metainf dir =$ {hibernate.dir}>
< include name =hibernate-service.xml/>
< / metainf>
< / jar>
< / target>

但是当我在hibernate-service.xml文件中使用错误形式的xml进行ant构建时,它不会失败。 更新甚至完全删除文件不会导致生成失败。这里有什么想法吗? 结束更新



听起来像让Hibernate输出SQL语句应该(如果一切正确设置)完全照顾它 - 这是否意味着log4j.properties中的设置在这里不会有什么区别? - 因为实际 在运行ant时更改输出。



编辑3:遇到其他怪异问题使用我的数据 har ,我完全删除了har文件,并使用 har ant构建目标重建它。突然一切都在工作!感谢国际象棋,因为他的棒极了。不能说我知道到底是什么,但我宁愿承认他的努力,而不是写和接受我自己的答案;如果您不是他,我很抱歉。

解决方案

正确的属性名称为 hibernate.show_sql ,它绝对有效。



确保您的 hibernate.cfg.xml 是正确的,它正在被拾起;对于您的 log4j.properties 文件也是如此。我知道这些似乎是愚蠢的建议,但他们占98%的缺少日志输出问题。



更新:我会更新答案而不是继续添加评论。
您需要确保您的 hibernate-service.xml 已被JBoss接收。检查的简单方法是向其添加语法错误(例如省略某个元素上的关闭括号),并查看JBoss是否在重新启动期间爆炸:-)它应该打包到 har 并作为构建过程的一部分进行部署,所以如果你意识到它不是由JBoss接收的,那就是这个地方。我将摆脱 hibernate.cfg.xml 中的冲突设置(例如,您指定为mbean属性的所有内容不应在 hibernate中复制。 cfg.xml )。对于这个问题,你甚至需要 hibernate.cfg.xml ?如果部署为 HAR ,则应自动扫描/拾取您的映射。


I haven't been able to get any more console output (to help with debugging) from Hibernate despite setting a few properties in the hibernate.cfg.xml file. For example, adding the line <property name="show_sql">true</property> did not, in fact, show SQL statements in the console.

I've also tried playing around with the contents of the log4j.properties file - like setting log4j.logger.org.hibernate=debug - with no luck. What am I missing?


Edit: the contents of the hibernate-service.xml file are

<server> 
    <mbean code="org.jboss.hibernate.jmx.Hibernate" 
       name="jboss.har:service=Hibernate_SMS"> 
        <attribute name="DatasourceName">java:/SMS_DS</attribute> 
        <attribute name="Dialect">org.hibernate.dialect.HSQLDialect</attribute> 
        <attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute> 
        <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
        <attribute name="ShowSqlEnabled">true</attribute>
    </mbean> 
</server>

I'm not 100% sure if this actually has any effect, though. That XML file is in the Eclipse project that handles my database stuff, but doesn't seem to be in the JBoss deploy directory.


Edit 2: This is definitely deployed as a HAR. That said, I'm pretty sure that I need hibernate.cfg.xml - I recall having problems when a mapping document was omitted as an entry in that file. I think the HAR is generated using ant - there's a target for it in the build.xml file:

<target name="har" depends="prepare" description="Builds the Hibernate HAR file">
    <mkdir dir="${class.root}" />
    <mkdir dir="${distribution.dir}" />

    <jar destfile="${distribution.dir}/${har.name}">                    
        <!-- include the hbm.xml files  -->
        <fileset dir="${class.root}">
            <include name="**/*.hbm.xml"/>
            <include name="com/[redacted]/sms/data/dto/*.class"/>
            <include name="com/[redacted]/sms/data/dto/base/*.class"/>
        </fileset>

        <!-- include jboss-service.xml -->
        <metainf dir="${hibernate.dir}">
            <include name="hibernate-service.xml"/>
        </metainf>
    </jar>
</target>

but when I do the ant build with incorrectly-formed xml in the hibernate-service.xml file, it doesn't fail. Update Even deleting the file entirely doesn't cause a build to fail. Any ideas here? End Update

It sounds like getting Hibernate to output SQL statements should (if everything's set up correctly) take care of it entirely - does that mean that the settings in log4j.properties won't make a difference here? - because that actually does change the output when running ant.

Edit 3: After running into other weird issues with my data har, I deleted the har file entirely and rebuilt it using the har ant build target. Suddenly everything's working! Thanks to chessplay for his awesome helpfulness. Can't say I know exactly what did it in the end, but I'd rather acknowledge his efforts than write and accept my own answer; My apologies if you're not a "he."

解决方案

The correct property name is hibernate.show_sql and it definitely works.

Make sure that your hibernate.cfg.xml is the right one and it is getting picked up; same goes for your log4j.properties file. I know those seem like dumb suggestions, but they account for 98% of "missing logging output" problems.

Update: I'll update the answer rather than keep adding comments. You do need to make sure your hibernate-service.xml is picked up by JBoss. The easy way to check is to add a syntax error to it (like omit a closing brace on some element) and see if JBoss blows up during restart :-) It should be packaged into har and deployed as part of your build process, so if you realize that it's not being picked up by JBoss, that's the place to look. I would get rid of conflicting settings in hibernate.cfg.xml (e.g. everything that you're specifying as mbean attributes should not be replicated in hibernate.cfg.xml). For that matter, do you even need hibernate.cfg.xml? If deployed as HAR, your mappings should be automatically scanned / picked up.

这篇关于如何从Hibernate获取更多的调试消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆