Hibernate version:latest
I'm running into this rather annoying situation. I have a job that grabs some RSS feeds and tries to insert the items into the database. The thing is that due to performance reason I don't want to check if the db has the item already retrieved and I try to re-enter it. I let the database reject it via a constraint mechanism.
The problem I'm having is that the logs are unusable due to the high number of traces that are meaningless.
My question is why in session.flush() is throwing and logging the exception instead of just throwing it ? To me constraint exception don't need the full stack trace, using log.error( message ) will do fine instead of log.error( message, e ).
Here's the stack trace. ( all these lines are just for one item )
2007-06-06 06:30:00,758 [QuartzScheduler_Worker-2]: WARN org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77) - SQL Error: 0, SQLState: null
2007-06-06 06:30:00,760 [QuartzScheduler_Worker-2]: ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - Batch entry 0 insert into public.news (VERSION, title, text, start_date, end_date, approved, sticky, source_name, date_created, date_modified, approved_by, source_link, css_style, created_by, modified_by, id) values (0, Title, <br>
<p><a href="http://domain.com/index.php?showimage=460"><img src="http://domain.com/rss_thumbs/img.jpg" width="250" height="193" border="0"></a></p><br>
Title<br>
<br>, NULL, NULL, 1, 0, "title", 2007-06-06 06:30:00.588000 -0500, NULL, 0,
http://domain.com/index.php?showimage=460, NULL, WEB, NULL, 550638) was aborted. Call getNextException to see the cause.
2007-06-06 06:30:00,781 [QuartzScheduler_Worker-2]: WARN org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77) - SQL Error: 0, SQLState: 23505
2007-06-06 06:30:00,782 [QuartzScheduler_Worker-2]: ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - ERROR: duplicate key violates unique constraint "unique_news_source_link"
2007-06-06 06:30:00,912 [QuartzScheduler_Worker-2]: ERROR org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
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:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at com.gsi.core.service.news.NewsServiceImpl.saveNews(NewsServiceImpl.java:134)
at com.gsi.core.service.news.NewsServiceImpl.update(NewsServiceImpl.java:109)
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:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at com.goodmedia.framework.core.aop.PerformanceMonitorInterceptor.invoke(PerformanceMonitorInterceptor.java:48)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at com.goodmedia.framework.core.aop.LoggingInterceptor.invoke(LoggingInterceptor.java:54)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at com.goodmedia.framework.core.aop.HibernateSessionInterceptor.invoke(HibernateSessionInterceptor.java:72)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy124.update(Unknown Source)
at com.gsi.job.NewsCollectionJob.execute(NewsCollectionJob.java:46)
at com.gsi.job.NewsCollectionJob.execute(NewsCollectionJob.java:59)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into public.news (VERSION, title, text, start_date, end_date, approved, sticky, source_name, date_created, date_modified, approved_by, source_link, css_style, created_by, modified_by, id) values (0, 'title' <br>