Hi,
Question 1:
========
I define transactions as follows :
Code:
...
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="target.service.research" class="com.mycompany.research.ResearchServiceImpl" lazy-init="true"/>
<bean name="service.research" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager"/>
<property name="target" ref="target.service.research"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="target.service.admin" class="com.mycompany.admin.AdminServiceImpl" lazy-init="true"/>
<bean name="service.admin" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager"/>
<property name="target" ref="target.service.admin"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
...
When I run my application it throws the following exception:
Code:
ERROR (JTATransaction.java:61) - Could not find UserTransaction in JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.hibernate.transaction.JTATransaction.begin(JTATransaction.java:58)
at org.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:53)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:426)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:281)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:217)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.save(Unknown Source)
at com.farbeyond.dbengine.ModelSet.save(ModelSet.java:565)
at com.farbeyond.test.crud.TestCRUDSEditing.testCRUDSEditing(TestCRUDSEditing.java:49)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I believe it thinks that I'm running my application within application server, in fact I'm not.
But when I change the definition as follows :
Code:
...
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="target.service.research" class="com.mycompany.research.ResearchServiceImpl" lazy-init="true"/>
<bean name="service.research" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager"/>
<property name="target" ref="target.service.research"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="service.admin" class="com.mycompany.admin.AdminServiceImpl" lazy-init="true"/>
...
my application runs without problem, as you can see from above definition it only works if I define transaction only for one service, no more.
What's the problem ?
Question 2:
=========
Actually class 'com.mycompany.admin.AdminServiceImpl' and class 'com.mycompany.admin.ResearchServiceImpl' derive from the same abstract class, i.e com.mycompany.base.AbstractServiceImpl in which all 'save*' and 'delete*' methods are defined.
Since 'com.mycompany.base.AbstractServiceImpl' is an abstract class is it possible to define transaction on this class once instead of in those two descendant classes ? So that I don't have to repeatedly define transactions everytime I create classes that derive from 'com.mycompany.base.AbstractServiceImpl' and the methods (save* and delete*) are located in their parent class anyway.
Thanks in advanced.
Setya