Results 1 to 3 of 3

Thread: Protected method: doGetTransaction()Ljava/lang/Object

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Posts
    2

    Default Protected method: doGetTransaction()Ljava/lang/Object

    Hi All,

    I'm working on an app using Wicket, Spring and iBatis. I'm new to Wicket and Spring, but have used iBatis about 5 years ago when I did more Java programming that I do now.

    I'm trying to implement Springs programmatic transaction management. From what I can tell, I think I have set everything up correctly, but am receiving an Exception "Protected method: doGetTransaction()Ljava/lang/Object" when calling the following code.
    Code:
    TransactionStatus status = txMgr.getTransaction(def);
    I don't see what I'm doing wrong, but it must be something. Any help would be greatly appreciated!

    My entire setup is as follows:

    applicationConext.xml

    Code:
    <bean id="dataSource"
            class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <property name="driverClassName">
            	<value>${jdbc.driver}</value>
            </property>      
    		<property name="url">
    			<value>${jdbc.url}</value>
    		</property>
            <property name="username">
            	<value>${jdbc.username}</value>
            </property> 
            <property name="password">
            	<value>${jdbc.password}</value>
            </property>
            <property name="maxActive" value="10"/>
            <property name="maxIdle" value="10"/> 
        </bean>
        <bean id="transactionManager"
    		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    			<property name="dataSource" ref="dataSource"/>
    	</bean>
    
    <bean id="sqlMap"
              class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            	<property name="configLocation">
                <value>classpath:SqlMapConfig.xml</value>
            </property>
            <property name="dataSource" ref="dataSource" />
        </bean>    
    
        <bean id="disService"
            class="com.brapp.ibatis.delegates.DisDelegate">
            <property name="sqlMapClient" ref="sqlMap" />
        </bean>
    BRApplication.java

    Code:
    public class BRApplication extends WebApplication implements ApplicationContextAware{
    	
    	private ApplicationContext ctx;
    	private DataSourceTransactionManager transMgr;
    	
    	private static ISpringContextLocator CTX_LOCATOR = new ISpringContextLocator() {
    		public ApplicationContext getSpringContext(){
    			return BRApplication.get().ctx;
    		}
    	};
    
    	@Override
    	protected void init(){
    		addComponentInstantiationListener(new SpringComponentInjector(
    		        this));
    		super.init();
    	}
    	
    	private <T> T createProxy(Class<T> clazz){
    		
    		return (T) LazyInitProxyFactory.createProxy(clazz, new SpringBeanLocator(clazz,CTX_LOCATOR));
    	}
    
    	public Class<HomePage> getHomePage()
    	{
    		return HomePage.class;
    	}	
    	
    	public static BRApplication get() {
    	    return (BRApplication) Application.get();
    	  }
    	
    	public DataSourceTransactionManager getTransactionManager(){
    		if(transMgr == null){
    			transMgr = createProxy(DataSourceTransactionManager.class);
    		}
    		return transMgr;
    	}
    
    	public void setApplicationContext(ApplicationContext applicationContext)
    			throws BeansException {
    		this.ctx = applicationContext;		
    	}
    
    	
    }
    Homepage.java

    Code:
    public class HomePage extends WebPage {
    
    	private static final long serialVersionUID = 1L;
    	
    	@SpringBean (name = "disService")
    	private DisDelegate dDelegate;
    
        public HomePage(final PageParameters parameters){
        	try{
    	       Dis newD = new Dis();
    	       newD.setDistrictName("MyDis");
    	       newD.setDistrictInitials("MyD");
    	       Integer myNewDstId = dDelegate.insertDis(newD);
                   add(new Label("myNewDis","My New District Id is " + myNewDstId.toString()));
    	    }catch(Exception e){
    	    		info(e.getMessage());
    	    	}
        	}
        }
    }
    DisDelegate.java

    Code:
    public class DisDelegate implements IDisService {
    	
    	private PlatformTransactionManager txMgr;
    
    public int insertDis(Dis d) throws Exception {
    		txMgr = (PlatformTransactionManager) BRApplication.get().getTransactionManager();
    		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    		def.setName("insDis");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    		TransactionStatus status = txMgr.getTransaction(def); //throws exception here
    		try{
    			int dstId = (Integer) sqlMap.insert("dis.insertDis", d);
    			return dstId;		
    		}catch(Exception e){
    			txMgr.rollback(status);
    			throw e;
    		}
    	}
    }

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hi

    Code:
    From what I can tell, I think I have set everything up correctly, but am receiving an 
    Exception "Protected method: doGetTransaction()Ljava/lang/Object" when calling the following code.
    Copy here the complete error stack trace, some times has nested errors messages with more information
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Jan 2011
    Posts
    2

    Default

    I've fixed the issue. I used a SpringBean Annotation in DisDelegate to create the PlatformTransactionManager

    Code:
    public class DisDelegate implements IBRService {
    	
    	@SpringBean (name = "transactionManager")
    	private PlatformTransactionManager txMgr;
    Then in my insertDis function I added the following:

    Code:
    public int insertDis(Dis d) throws Exception {
    		// Injects the spring bean(s)
    		  InjectorHolder.getInjector().inject(this);
    Not sure why my Application.get().getTransactionManager() call didn't work. Maybe something to do with the createProxy call???

    I tried to put the InjectorHolder call in the DisDelegate constructor, but then my webapp would not start. Maybe because DisDelegate is created in Homepage.java via a SpringBean as well.

    Code:
    public class HomePage extends WebPage {
    
    	private static final long serialVersionUID = 1L;
    	
    	@SpringBean (name = "disService")
    	private DisDelegate dDelegate;
    ....

Posting Permissions

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