Results 1 to 4 of 4

Thread: Uncatchable hibernate exceptions when using AutoProxyCreator

  1. #1
    Join Date
    Aug 2004
    Posts
    6

    Default Uncatchable hibernate exceptions when using AutoProxyCreator

    When using a BeanNameAutoProxyCreator with Hibernate DAO classes, spring 1.1.5 fails to catch net.sf.hibernate.StaleObjectStateExceptions and convert them to DataAccessExceptions.

    When I do not use the auto proxy, I can catch and deal with hibernate exceptions, but when the proxy is in place, the exceptions are magically thrown, and there's nothing I can do about it.

    Is this by design? If so, how can I use the auto proxy features in spring and still handle optimistic locking failures?

    Thanks,
    Josh

    Code:
    	<bean id="autoProxyCreator"
    		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    		<property name="interceptorNames">
    			<list>
    				<idref bean="matchNameTxInterceptor" />
    			</list>
    		</property>
    		<property name="beanNames">
    			<list>
    				<value>org_sakaiproject_service_gradebook_GradebookService</value>
    				<value>org_sakaiproject_tool_gradebook_business_GradebookManager</value>
    				<value>org_sakaiproject_tool_gradebook_business_GradeManager</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="matchNameTxInterceptor"
    		class="org.springframework.transaction.interceptor.TransactionInterceptor">
    		<property name="transactionManager">
    			<ref bean="gradebookTransactionManager" />
    		</property>
    		<property name="transactionAttributeSource">
    			<ref bean="matchNameWithPropReq" />
    		</property>
    	</bean>
    
    	<bean id="matchNameWithPropReq"
    		class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    		<property name="properties">
    			<props>
    				<prop key="add*">PROPAGATION_REQUIRED</prop>
    				<prop key="create*">PROPAGATION_REQUIRED</prop>
    				<prop key="update*">PROPAGATION_REQUIRED</prop>
    				<prop key="remove*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    [/code]

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    spring 1.1.5 fails to catch net.sf.hibernate.StaleObjectStateExceptions and convert them to DataAccessExceptions
    Strange...can you provide a trace. Spring should at least convert it to UncategorizedDataAccessException or a subclass of it.

    but when the proxy is in place, the exceptions are magically thrown, and there's nothing I can do about it.
    Are you trying to catch them behind the proxy - some exceptions may not be thrown until control returns to the proxy, and it flushes/commits.

  3. #3
    Join Date
    Aug 2004
    Posts
    6

    Default

    Strange...can you provide a trace.
    Strange indeed. I can't even try to catch the net.sf.hibernate.StaleObjectStateException since hibernateTemplate.execute doesn't throw this checked exception. Here's the stack trace:

    (thanks for having a look!)

    Code:
    Jul 6, 2005 8&#58;13&#58;22 PM net.sf.hibernate.StaleObjectStateException <init>
    WARNING&#58; An operation failed due to stale data
    net.sf.hibernate.StaleObjectStateException&#58; Row was updated or deleted by another transaction &#40;or un
    saved-value mapping was incorrect&#41; for org.sakaiproject.tool.gradebook.AssignmentGradeRecord instanc
    e with identifier&#58; 103
            at net.sf.hibernate.persister.AbstractEntityPersister.check&#40;AbstractEntityPersister.java&#58;513
    &#41;
            at net.sf.hibernate.persister.EntityPersister.update&#40;EntityPersister.java&#58;664&#41;
            at net.sf.hibernate.persister.EntityPersister.update&#40;EntityPersister.java&#58;621&#41;
            at net.sf.hibernate.impl.ScheduledUpdate.execute&#40;ScheduledUpdate.java&#58;52&#41;
            at net.sf.hibernate.impl.SessionImpl.execute&#40;SessionImpl.java&#58;2449&#41;
            at net.sf.hibernate.impl.SessionImpl.executeAll&#40;SessionImpl.java&#58;2435&#41;
            at net.sf.hibernate.impl.SessionImpl.execute&#40;SessionImpl.java&#58;2393&#41;
            at net.sf.hibernate.impl.SessionImpl.flush&#40;SessionImpl.java&#58;2261&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
            at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
            at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
            at org.springframework.orm.hibernate.HibernateTemplate$CloseSuppressingInvocationHandler.inv
    oke&#40;HibernateTemplate.java&#58;1196&#41;
            at $Proxy3.flush&#40;Unknown Source&#41;
            at org.sakaiproject.tool.gradebook.business.impl.GradeManagerHibernateImpl$5.doInHibernate&#40;G
    radeManagerHibernateImpl.java&#58;282&#41;
            at org.springframework.orm.hibernate.HibernateTemplate.execute&#40;HibernateTemplate.java&#58;312&#41;
            at org.springframework.orm.hibernate.HibernateTemplate.execute&#40;HibernateTemplate.java&#58;289&#41;
            at org.sakaiproject.tool.gradebook.business.impl.GradeManagerHibernateImpl.updateAssignmentG
    radeRecords&#40;GradeManagerHibernateImpl.java&#58;295&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
            at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
            at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection&#40;AopUtils.java&#58;284
    &#41;
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint&#40;ReflectiveMe
    thodInvocation.java&#58;155&#41;
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed&#40;ReflectiveMethodInvo
    cation.java&#58;122&#41;
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke&#40;TransactionInte
    rceptor.java&#58;56&#41;
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed&#40;ReflectiveMethodInvo
    cation.java&#58;144&#41;
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke&#40;JdkDynamicAopProxy.java&#58;174&#41;
            at $Proxy0.updateAssignmentGradeRecords&#40;Unknown Source&#41;
            at org.sakaiproject.tool.gradebook.ui.AssignmentDetailsBean.saveScores&#40;AssignmentDetailsBean
    .java&#58;267&#41;

  4. #4
    Join Date
    Aug 2004
    Posts
    6

    Default

    Are you trying to catch them behind the proxy - some exceptions may not be thrown until control returns to the proxy, and it flushes/commits.
    I'm not sure what "behind the proxy means" (I'm new to AOP), but I am trying to catch the exceptions in my DAO (in this case, GradeManagerHibernateImpl.java) and not in the transaction proxy (which is the stock org.springframework.transaction.interceptor.Transa ctionInterceptor).

Similar Threads

  1. Replies: 6
    Last Post: Oct 11th, 2007, 02:19 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. No rollback with exceptions using Hibernate
    By elwell642 in forum Data
    Replies: 4
    Last Post: Feb 8th, 2005, 08:52 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Hibernate checked Exceptions
    By ndijkstra in forum Data
    Replies: 3
    Last Post: Oct 20th, 2004, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •