B T
B T

Reputation: 60875

How can I force java Hibernate to throw exceptions instead of logging logj4 messages?

Annoyingly, Hibernate in some cases seems to like to write a log to log4j itself. I don't want it to. I would like it to throw an exception when something goes wrong, like a good library would.

Does anyone know if this is possible, and more importantly, how do i do it?

For example, I'm getting this ERROR level log "Deadlock found when trying to get lock; try restarting transaction" . It wouldn't be so bad if it at least included a stack trace, or maybe the query that resulted in that deadlock. But it doesn't, so its been hard to debug some of these cases.

I've looked through the hibernate mapping dtd file, the hibernate configuration xml file, and the hibernate configuration dtd file, but nothing jumps out at me as a way to control logging.

I see the following lines in my log4j.properties file:

# Don't log Hibernate flushing exceptions (usually StaleStateExceptions)
log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=FATAL
log4j.logger.org.hibernate.jdbc.AbstractBatcher=FATAL

Will hibernate throw an exception if i label certain things as "FATAL" ?

I'm a little lost in the Hibernate swamp, so I'd appreciate some direction. As context, I've been working with hibernate for 2 years, but I'm by no means an expert at it.

Upvotes: 0

Views: 1042

Answers (1)

B T
B T

Reputation: 60875

What we've found is that hibernate does in fact throw exceptions, but it also logs. We set our log4j such that hibernate won't log exceptions from specific classes just like i wrote in my question:

# Don't log Hibernate flushing exceptions (usually StaleStateExceptions)
log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=FATAL

Upvotes: 1

Related Questions