避免在日志文件中打印默认的hibernate异常日志报告

时间:2016-12-09 03:15:54

标签: hibernate logging printing default

我写了一个java程序,在其中使用了 hibernate 。在Linux中运行该java程序时,我将hibernate日志打印到日志文件中,由于内置的​​异常报告(例如约束声音异常,启动会话工厂等)而占用大量内存。但我不希望hibernate内置日志语句打印以避免内存占用。我该怎么办?

我不想在日志文件中打印的异常日志报告:

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at com.tcs.rapdrp.main.MyThread.run(InsertionData.java:238)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (tablename.columnname) violated
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10070)
    at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242) ... 8 more

1 个答案:

答案 0 :(得分:0)

在我看来,这正是日志文件的用途 - 捕获异常和相关的堆栈跟踪,以便您可以查明出错的地方。 日志保存在纯文本文件中,我认为在正常情况下不会导致内存问题。

使用记录器工具(例如log4j)并更改日志级别,以便您可以禁用日志。 检查是否已将日志级别设置为应用程序的DEBUG。您可以根据需要将其更改为ERRORWARNING