休眠:OutOfMemoryError在打印日志消息时持续存在Blob [英] Hibernate: OutOfMemoryError persisting Blob when printing log message

查看:239
本文介绍了休眠:OutOfMemoryError在打印日志消息时持续存在Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个休眠实体:

@Entity
class Foo {
    //...
    @Lob
    public byte[] getBytes() { return bytes; }
    //....
}

我的VM配置为最大堆大小为512 MB.当我尝试保留具有75 MB大对象的对象时,出现OutOfMemoryError.

My VM is configured with a maximum heap size of 512 MB. When I try to persist an object which has a 75 MB large object, I get an OutOfMemoryError.

堆栈跟踪中的方法名称(StringBuilder,ByteArrayBlobType.toLoggableString,pretty.Printer.toString)表明hibernate正在尝试编写包含我的对象的非常大的日志消息.

The names of the methods in the stack trace (StringBuilder, ByteArrayBlobType.toLoggableString, pretty.Printer.toString) suggest that hibernate is trying to write a very large log message that contains my object.

我是否正确地解释了为什么休眠使用了如此多的内存?解决此问题的最简单方法是什么?

Am I correct about why hibernate is using so much memory? What is the simplest way to work around this problem?

java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:44)
at java.lang.StringBuilder.<init>(StringBuilder.java:81)
at org.hibernate.type.ByteArrayBlobType.toString(ByteArrayBlobType.java:117)
at org.hibernate.type.ByteArrayBlobType.toLoggableString(ByteArrayBlobType.java:127)
at org.hibernate.pretty.Printer.toString(Printer.java:53)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.jboss.seam.persistence.HibernateSessionProxy.flush(HibernateSessionProxy.java:181)

推荐答案

我解决了这个问题.关闭日志记录确实解决了问题,但是我不明白在JBoss应用程序服务器下运行时,服务器自己的log4j.xml文件会覆盖我在应用程序的类路径中放置的内容.

I solved the problem. Turning off logging did fix the problem, but I didn't understand that when running under the JBoss application server, the server's own log4j.xml file overrides whatever I put the in classpath of the application.

我打开了/jboss-4.2.3.GA/server/default/conf/log4.xml,并将其插入:

I opened up /jboss-4.2.3.GA/server/default/conf/log4.xml, and inserted this:

<category name="org.hibernate">
    <priority value="ERROR"/>
</category>

这可以解决我遇到的问题.

This fixes the issue I am seeing.

这篇关于休眠:OutOfMemoryError在打印日志消息时持续存在Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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