Results 1 to 8 of 8

Thread: Problem when using <tx:annotation-driven>

  1. #1
    Join Date
    Aug 2007
    Posts
    6

    Default Problem when using <tx:annotation-driven>

    Hi,
    I am trying to get the annotational transactionManager working for me.
    But I am getting this weird problem, I hope some one can give me a lead
    on this.

    I am using spring-framework-2.0.6 and

    here is part of my applicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
        
        <!-- enable the configuration of transactional behavior based on annotations -->
        <tx:annotation-driven transaction-manager="txManager"/>
    	
    	<!-- a PlatformTransactionManager is still required -->
    	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	  <property name="sessionFactory" ref="beanSessionFactory" />
    	</bean>
    
    	<bean id="wijisDataSource"
    		class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close">
    		<property name="driverClass">
    			<value>@database.driver@</value>
    		</property>
    		<property name="jdbcUrl">
    			<value>@database.url@</value>
    		</property>
    		<property name="user">
    			<value>@database.user@</value>
    		</property>
    		<property name="password">
    			<value>@database.password@</value>
    		</property>
    		<property name="minPoolSize">
    				<value>5</value>
    		</property>
    		<property name="maxPoolSize">
    			<value>20</value>
    		</property>
    		<property name="maxIdleTime">
    			<value>600</value>
    		</property>
    		<property name="testConnectionOnCheckout">
    			<value>false</value>
    		</property>		
    	</bean>
    
    	<bean id="dom4jHibernateProperties"
    		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    		<property name="properties">
    			<props>
    				<prop key="hibernate.hbm2dll.auto">update</prop>
    				<prop key="hibernate.dialect">@hibernate.dialect@</prop>
    				<prop key="hibernate.query.substitutions">
    					true 'T', false 'F'
    				</prop>
    				<prop key="hibernate.show_sql">false</prop>
    				<prop key="hibernate.default_entity_mode">dom4j</prop><!-- This is needed for the XML <->DB Mapping -->
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="javaHibernateProperties"
    		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    		<property name="properties">
    			<props>
    				<prop key="hibernate.hbm2dll.auto">update</prop>
    				<prop key="hibernate.dialect">@hibernate.dialect@</prop>
    				<prop key="hibernate.query.substitutions">
    					true 'T', false 'F'
    				</prop>
    				<prop key="hibernate.show_sql">false</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="beanSessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref bean="wijisDataSource" />
    		</property>
    		<property name="hibernateProperties">
    			<ref bean="javaHibernateProperties" />
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>UserSession.hbm.xml</value>
    				<value>Jurisdiction.hbm.xml</value>
    				<value>Audit.hbm.xml</value>
    				<value>WijisPointerJava.hbm.xml</value>
    			    <value>Organization.hbm.xml</value>
    				<value>Host.hbm.xml</value>
    				<value>Roles.hbm.xml</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="pointerDAOTarget"
    		class="gov.wisconsin.wijis.gateway.persistence.PointerDAOHibernateImpl">
    		<property name="sessionFactory">
    			<ref bean="beanSessionFactory" />
    		</property>
    		<property name="maxRecordsToReturn"><value>500</value></property>
    		<property name="useMaxRecordsField"><value>true</value></property>		
    		<property name="directoryForDownload"><value>/usr/local/apache-tomcat-5.5.17/temp/</value></property>				
    		<property name="jurisdiction"><ref bean="jurisdictionDAOTarget" /></property>				
    	</bean>
    
    ... ....

    With it, I can deploy the app and all the beans were created. I have not added any
    @Transactional to my DAO code yet.
    The problem is, I can run the app, but my search, which returns a xml document and we have a chokePointer interceptor on it, breaks.

    And here is the error message:

    Code:
    2007-08-15 16:56:24,266 DEBUG 
    [gateway.persistence.PointerDAOHibernateImpl] - starting XML search
    2007-08-15 16:56:24,325 DEBUG 
    [gateway.persistence.PointerDAOHibernateImpl] - finishing XML search
    2007-08-15 16:56:24,542 DEBUG 
    [gateway.persistence.PointerDAOHibernateImpl] - result size:93
    2007-08-15 16:56:24,586 ERROR 
    [gateway.serviceimpl.SearchServiceHelperThread] - Search Error
    java.lang.ClassCastException: org.apache.xmlbeans.impl.store.Xobj$DocumentXobj
            at gov.wisconsin.wijis.gateway.interceptors.SearchServiceChokepoint.invoke(SearchServiceChokepoint.java:20)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
            at $Proxy41.searchPerson(Unknown Source)
            at gateway.serviceimpl.SearchServiceHelperThread.run(SearchServiceHelperThread.java:67)
    And here is the chokePoint code:
    Code:
    package gateway.interceptors;
    
    import gateway.serviceimpl.SearchResults;
    import specs.schemas.gateway.service.search.v11.SearchErrorDocument;
    import specs.schemas.gateway.service.search.v11.SearchResponseDocument;
    import specs.schemas.gateway.service.search.v11.SearchTooManyRecordsDocument;
    
    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class SearchServiceChokepoint implements MethodInterceptor {
    	private static final Log log = LogFactory.getLog(SearchServiceChokepoint.class);
    	private XMLDocumentChokepoint xmlChokepointInstance; 
    	
    	public Object invoke (MethodInvocation invocation) throws Throwable {
    		
    		//Here is where search actually gets called
    		SearchResults returnValue = (SearchResults) invocation.proceed(); //It breaks here. 
    
    		//Do post search processing here
    		SearchResponseDocument resultsDocument= returnValue.getResponse();
    		if (resultsDocument instanceof SearchTooManyRecordsDocument || resultsDocument instanceof SearchErrorDocument)
    		{
    			log.debug("This is not a results doc, don't filter");
    			return new SearchResults (resultsDocument);
    		}	
    		
    		resultsDocument = xmlChokepointInstance.filterXmlDocument(resultsDocument);
    		
    		/* This was burning too many CPU cycles, changed it from DOM4j to xmlbeans
    		Document docFromChokepoint;
    		Document xmlResults = (Document)resultsDocument.getDomNode();
    		docFromChokepoint = xmlChokepointInstance.filterXmlDocument(xmlResults);        
            SearchResponseDocument searchResponse = SearchResponseDocument.Factory.parse(docFromChokepoint);
            */
    		
            return new SearchResults (resultsDocument);
    	}
    Any ideas?
    Thanks.

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    I don't think tx:annotation-driven tag has anything to do with your exception. The exception appears only when that tag is added to your config file ?

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you are using @Transactional it's going to be applying AOP to the target, you need to ensure you are casting to the interface of the target instead of the class. Otherwise you need to use proxyTargetClass. If that's not the problem any chance you could supply a few more details.
    Last edited by karldmoore; Aug 27th, 2007 at 02:02 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  4. #4
    Join Date
    Aug 2007
    Posts
    6

    Unhappy

    Yes. At first I googled the exception, and people were saying it might be not compatible versions of XMLbeans and Saxon, I tried to use different jars of saxon, I am using xmlbeans 2.2, so according to the posts, I have to use saxon8.6.1 or higher. But it
    didn't help.
    And when I remove the tx:annotation-driven tag, I can do the search again, everything looks normal. But of course I want to use that tag. I will try <tx:advice> today.

    Quote Originally Posted by Andrei Stefan View Post
    I don't think tx:annotation-driven tag has anything to do with your exception. The exception appears only when that tag is added to your config file ?

  5. #5
    Join Date
    Aug 2007
    Posts
    6

    Default

    I am not using @Transactional anywhere in the code yet. Let me comb through the problem once again to see what I should post here for better help. Thanks.

    Quote Originally Posted by karldmoore View Post
    If you are using @Transactional it's going to be applying AOP to the target, you need to ensure you are casting to the interface of the target instead of the class. Otherwise you need to use proxyTargetClass. If that's not the problem any chance you could supply a few more details.

  6. #6
    Join Date
    Aug 2007
    Posts
    6

    Default A little more info.

    Note that in the following piece of code, the red line is where the exception
    is thrown when I put the <tx:annotation-driven> tag into the applicationContext.xml.

    What happens is when <tx:annotation-driven> tag is there, the function call returns
    an object of type org.apache.xmlbeans.impl.store.Xobj$DocumentXobj

    And when the tag is not there, the returned object's type is wijis.gateway.servic
    eimpl.SearchResults, which is exactly what I want.

    I am not so familiar with this part of the code, so I am digging it right now. But if you
    have any ideas, please speak out. Thanks a lot.

    Code:
    package wijis.gateway.interceptors;
    
    import wijis.gateway.serviceimpl.SearchResults;
    import wijis.specs.schemas.gateway.service.search.v11.SearchErrorDocument;
    import wijis.specs.schemas.gateway.service.search.v11.SearchResponseDocument;
    import wijis.specs.schemas.gateway.service.search.v11.SearchTooManyRecordsDocument;
    
    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class SearchServiceChokepoint implements MethodInterceptor {
    	private static final Log log = LogFactory.getLog(SearchServiceChokepoint.class);
    	private XMLDocumentChokepoint xmlChokepointInstance; 
    	
    	public Object invoke (MethodInvocation invocation) throws Throwable {
    		
    		//Here is where search actually gets called
    		SearchResults returnValue = (SearchResults) invocation.proceed();
    
    		//Do post search processing here
    		SearchResponseDocument resultsDocument= returnValue.getResponse();
    		if (resultsDocument instanceof SearchTooManyRecordsDocument || resultsDocument instanceof SearchErrorDocument)
    		{
    			log.debug("This is not a results doc, don't filter");
    			return new SearchResults (resultsDocument);
    		}	
    		
    		resultsDocument = xmlChokepointInstance.filterXmlDocument(resultsDocument);
    		
    		/* This was burning too many CPU cycles, changed it from DOM4j to xmlbeans
    		Document docFromChokepoint;
    		Document xmlResults = (Document)resultsDocument.getDomNode();
    		docFromChokepoint = xmlChokepointInstance.filterXmlDocument(xmlResults);        
            SearchResponseDocument searchResponse = SearchResponseDocument.Factory.parse(docFromChokepoint);
            */
    		
            return new SearchResults (resultsDocument);
    	}
    
    	public XMLDocumentChokepoint getXmlChokepointInstance() {
    		return xmlChokepointInstance;
    	}
    
    	public void setXmlChokepointInstance(XMLDocumentChokepoint xmlChokepointInstance) {
    		this.xmlChokepointInstance = xmlChokepointInstance;
    	}
    
    }

  7. #7
    Join Date
    Mar 2007
    Posts
    515

    Default

    Take a look at this bug and try performing a test using the latest Spring version.

  8. #8
    Join Date
    Aug 2007
    Posts
    6

    Default

    Thanks a lot, Andrei.

    I downloaded spring-framework-2.0.7 and replace the spring.jar in my app with the new
    spring.jar, looks like that solves the problem.

    Thanks again.
    Haiqi.

    Quote Originally Posted by Andrei Stefan View Post
    Take a look at this bug and try performing a test using the latest Spring version.
    Last edited by Haiqi; Aug 17th, 2007 at 12:17 PM.

Posting Permissions

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