Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTA @transaction not commited

 
vaijesh basavarajappa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vaijesh basavarajappa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic