wood burning stoves 2.0*
The moose likes Spring and the fly likes JTA @transaction not commited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JTA @transaction not commited" Watch "JTA @transaction not commited" New topic
Author

JTA @transaction not commited

vaijesh basavarajappa
Greenhorn

Joined: Feb 04, 2013
Posts: 5
In My service layer i am using @transaction.From service i am calling DAO

Service layer code:



DAO COde:


Business Object:


Spring Configuration:

<tx:annotation-driven />
<tx:jta-transaction-manager />
<bean id="entitymanager"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaV endorAdapter" >
<property name="database" value="DB2" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.DB2Dictionary" />
</bean>
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />



Persistence xml:

<persistence-unit name="X" transaction-type="JTA">
<jta-data-source>jdbc/datasource</jta-data-source>
<class>com.businessobjects.Location</class>
</persistence-unit>

When i run on Websphere application server,my location object is not saved.I am not getting any error.No sql statement are showed on console

If i put @Transaction on DAO addLocation method.it is getting saved(insert statement are showed).But i need to put on service layer so that i can call other DAo methods in the same transaction.

Console stackTrace is:

INFO [WebContainer : 2] openjpa.Runtime - Starting OpenJPA 2.1.1-SNAPSHOT
[2/14/13 22:53:50:868 IST] 00000032
SystemErr R 19494 TRACE [WebContainer : 2] openjpa.jdbc.SQL - <t 31882503, conn 29839727> executing stmnt 29839913 SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1
[2/14/13 22:53:50:868 IST] 00000032
SystemErr R 19494 TRACE [WebContainer : 2] openjpa.jdbc.SQL - <t 31882503, conn 29839727> [0 ms] spent


Please help me.

Thanks
vaijesh
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

How is addLocation() being called. Are you wiring in ILocation in as a spring bean and calling it through the proxy? With the defaults no proxy = no transaction.


[How To Ask Questions][Read before you PM me]
vaijesh basavarajappa
Greenhorn

Joined: Feb 04, 2013
Posts: 5
Thanks Bill for the reply.It got solved.but really i dont know the reason.

I have java project and web project bundled as Ear.In java project context i have defined <tx:annotation-driven /> and in web project i have defined <context:annotation-config />.
Actually Transaction was not active because i have defined <context:annotation-config /> and <tx:annotation-driven /> in different root context .
After moving both in single context it got worked.The transaction have become active.

Could you please explain me why transaction was not active when defined in different context.

Thanks
Vaijesh
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

This is a problem that crops up with only the <context:annotation-config/> tag. From the reference manual

Note that <context:annotation-config/> only looks for annotations on beans in the same application context it is defined in. This means that, if you put <context:annotation-config/> in a WebApplicationContext for a DispatcherServlet, it only checks for @Autowired beans in your controllers, and not your services


I prefer to use the component-scan tag which does everything this tag does (and more) and does not have this restriction.

In other words if you use this tag you must add it in every context it is needed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTA @transaction not commited