-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ConstraintViolationException logged before being thrown
PostPosted: Thu Aug 25, 2005 2:22 pm 
Newbie

Joined: Thu Aug 25, 2005 2:10 pm
Posts: 1
It appears that hibernate logs ConstraintViolationException at ERROR level before actually throwing it. It sort of screws me up because I am actually expecting it under some conditions and don't want the log to be polluted with meaningless exceptions.

Any way to tell hibernate not to do it short of changing the log levels?




code:

try {

if (counter.isPersisted()) {
session.update(counter);
} else {
session.persist(counter);
session.flush();
counter.setPersisted(true);
}

} catch (ConstraintViolationException ex) {
//insert failed - try update
session.evict(counter);
session.update(counter);
session.flush();
counter.setPersisted(true);
}


despite of catch the log says:

14:00:41,782 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at COM.soundbite.biz.workflow.MessageCounterServiceImpl.presist(MessageCounterServiceImpl.java:96)
at COM.soundbite.biz.workflow.MessageCounterServiceImpl.persist(MessageCounterServiceImpl.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
.......
COM.soundbite.biz.workflow.SubCampaignMessageCounterServiceImplTest.testProcessMessage(SubCampaignMessageCounterServiceImplTest.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (MKOLESNIK.SYS_C0083091) violated

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at COM.soundbite.base.jdbc.driver.StatementHandler.execute(StatementHandler.java:78)
at COM.soundbite.base.jdbc.driver.BaseTracer.invoke(BaseTracer.java:80)
at $Proxy4.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 35 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 9:47 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
Why would you want to have constraint violations to occur in some cases?

If they happen, it is an error.

If you really want to you can suppress the error by telling log4j to not log error level warnings for that specific error class.


However, couldn't you simply that block of code by calling
session.saveOrUpdate(counter); ?

_________________
Joe W


Top
 Profile  
 
 Post subject: Re: ConstraintViolationException logged before being thrown
PostPosted: Sat Jan 09, 2010 7:04 am 
Newbie

Joined: Sun Oct 14, 2007 6:51 am
Posts: 2
@jw3525: it is not feasible to suppress that log message, precisely because it is at level ERROR. In order to suppress that category, one needs to turn it off completely, and that is not always possible. Regarding your first question, performance can be a reason. If I need to insert a million records and I expect that maybe a 1000 of them will fail, I don't want to check their existence first, I want to catch the exception, and I don't want garbage in my logs.

Also, it is not an hibernate error if a ConstraintViolationException occurs, if anything at all then it is an application error. Hibernate should let me decide if/how/when to log it, and not to pollute my logs.

Please see here -> http://opensource.atlassian.com/project ... e/HHH-3731


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.