Announcement Announcement Module
Collapse
No announcement yet.
catching DataAccessException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • catching DataAccessException

    I have the following code:

    DAO Implementation
    Code:
    	public void save(Holiday holiday) {
    		getHibernateTemplate().saveOrUpdate(holiday);
    	}
    BO Implementation
    Code:
    	public void saveHoliday(Holiday holiday) throws BusinessException {
    		try {
    			holidayDAO.save(holiday);
    		} catch (DataAccessException dae) {
    			System.err.println("convert this to a BusinessException with relevant info for the user:" + dae.getMessage());
    		}
    	}
    I would except if a DataAccessException is thrown I now catch it and the no other exception is shown, but I get the following output in my console.

    Code:
    [20/05/05 10:05:50:665 CEST] 5a2387f1 JDBCException W org.hibernate.util.JDBCExceptionReporter  SQL Error: -803, SQLState: 23505
    
    [20/05/05 10:05:50:680 CEST] 5a2387f1 JDBCException E org.hibernate.util.JDBCExceptionReporter  [SQL0803] Dubbele sleutelwaarde opgegeven.
    
    [20/05/05 10:05:50:696 CEST] 5a2387f1 JDBCException W org.hibernate.util.JDBCExceptionReporter  SQL Error: -803, SQLState: 23505
    
    [20/05/05 10:05:50:696 CEST] 5a2387f1 JDBCException E org.hibernate.util.JDBCExceptionReporter  [SQL0803] Dubbele sleutelwaarde opgegeven.
    
    [20/05/05 10:05:50:743 CEST] 5a2387f1 AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener  Could not synchronize database state with session
    
    [20/05/05 10:05:50:758 CEST] 5a2387f1 AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener  TRAS0014I: The following exception was logged org.hibernate.exception.ConstraintViolationException: could not insert: [be.oz.common.vo.Holiday]
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1859)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2190)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    	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:726)
    	at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:210)
    	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
    	at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:610)
    	at be.oz.common.dao.iSeries.HolidayDAOImpl.save(HolidayDAOImpl.java:60)
    	at be.oz.common.bo.HolidayBO.saveHoliday(HolidayBO.java:53)
    	at be.oz.methodology.web.action.MethodologyAction.saveHoliday(MethodologyAction.java:333)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
    	at be.oz.common.struts.gui.action.BaseAction.execute(BaseAction.java:77)
    	at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    	at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java(Inlined Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
    	at be.oz.common.filter.AbstractUserNameFilter.doFilter(AbstractUserNameFilter.java:69)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:137)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at be.oz.common.filter.AbstractMenuFilter.doFilter(AbstractMenuFilter.java:61)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:166)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java(Compiled Code))
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java(Compiled Code))
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    	at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
    	at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
    	at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    	at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
    	at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
    	at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    	at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    	at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
    	at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:443)
    	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
    Caused by: com.ibm.websphere.ce.cm.DuplicateKeyException: [SQL0803] Dubbele sleutelwaarde opgegeven.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java(Compiled Code))
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code))
    	at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapExceptionHelper(GenericDataStoreHelper.java:473)
    	at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapException(GenericDataStoreHelper.java:516)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.mapException(WSJdbcUtil.java:824)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:480)
    	at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1843)
    	... 58 more
    .
                                     org.hibernate.exception.ConstraintViolationException: could not insert: [be.oz.common.vo.Holiday]
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1859)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2190)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    	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:726)
    	at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:210)
    	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
    	at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:610)
    	at be.oz.common.dao.iSeries.HolidayDAOImpl.save(HolidayDAOImpl.java:60)
    	at be.oz.common.bo.HolidayBO.saveHoliday(HolidayBO.java:53)
    	at be.oz.methodology.web.action.MethodologyAction.saveHoliday(MethodologyAction.java:333)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
    	at be.oz.common.struts.gui.action.BaseAction.execute(BaseAction.java:77)
    	at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    	at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java(Inlined Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java(Compiled Code))
    	at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
    	at be.oz.common.filter.AbstractUserNameFilter.doFilter(AbstractUserNameFilter.java:69)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:137)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at be.oz.common.filter.AbstractMenuFilter.doFilter(AbstractMenuFilter.java:61)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:166)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java(Compiled Code))
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java(Compiled Code))
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    	at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
    	at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
    	at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    	at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
    	at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
    	at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    	at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    	at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
    	at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:443)
    	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
    Caused by: com.ibm.websphere.ce.cm.DuplicateKeyException: [SQL0803] Dubbele sleutelwaarde opgegeven.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java(Compiled Code))
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code))
    	at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapExceptionHelper(GenericDataStoreHelper.java:473)
    	at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapException(GenericDataStoreHelper.java:516)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.mapException(WSJdbcUtil.java:824)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:480)
    	at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
    	at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1843)
    	... 58 more
    
    [20/05/05 10:05:50:774 CEST] 5a2387f1 SystemErr     R convert this to a BusinessException with relevant info for the user:Hibernate operation: [SQL0803] Dubbele sleutelwaarde opgegeven.; nested exception is com.ibm.websphere.ce.cm.DuplicateKeyException: [SQL0803] Dubbele sleutelwaarde opgegeven.
    only the last line shows the DataAccessException catch block.
    As you can I see I get a duplicate key error. Problem is I can't catch the hibernate exceptions. They are thrown anyway, even if I surround the saveOrUpdate with a catch (Exception e) block...

    is this normal behaviour? Because I don't like the long stackTraces in my log

  • #2
    You have to adjust your Hibernate logging configuration; in your case HB logs the error and then your application.

    Comment


    • #3
      that's what I thought myself, but I can't seem to find a way to turn this loggin off...

      i've set up a very simple log4j propertie file, but this doesn't change a thing to the hibernate/spring logging:

      here I set all logging off !!!! but I still get the above error
      Code:
      ## direct log messages to stdout ###
      log4j.appender.stderr=org.apache.log4j.ConsoleAppender
      log4j.appender.stderr.Target=System.err
      log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
      log4j.appender.stderr.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
      
      ### set log levels - for more verbose logging change 'info' to 'debug' ###
      
      log4j.rootLogger=off, stderr
      but my own logging (eg. Logger.getRootLogger().info("this is a test"); )works perfectly...

      it's like spring/hibernate doesn't read the log4j.properties...

      I know it's a bit off-topic, but I would like to know what's going wrong with my hibernate/spring logging...

      Comment


      • #4
        in the mean time I found a solution to the logging.

        it's because websphere was using it's own implementation of the logging factory. I changed it so it's using log4j now :-)

        for future users with same problems check this site:

        http://www-1.ibm.com/support/docview...id=swg27004610

        Comment

        Working...
        X