Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Transaction not propagated between bundles (Service & DAO) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction not propagated between bundles (Service & DAO)

    HI,

    I have created a JPA project using EclipseLink JPA 1.x version and deployed in ServiceMix OSGI server 4.X running Apache Felix Server. The project consists of several bundles : model, dao and service layer. To define services as transactional, I have used the annotation @Transactional. Unfortunately, the transaction is not started and not committed when I call the method of my service (bundle Service). It works fine when @Transactional is defined in the bundle DAO.

    Remark : I use Spring DM 1.2. and Spring 2.5.6.SECO1

    Can someone tell me what I doing wrong (if this is the case) ?
    It should be interesting that the Petclinic example implements also a Service layer ;-)

    A. Bundle Service

    1) Class Service

    @Service("sapService")
    @Transactional
    public class PersistenceImpl implements Persistence {

    @Autowired
    private SapDocumentDAO sapDocumentDAO;

    @Transactional
    public void save(@Body final FinishedTireDocument finishedTiredDocument, Exchange exch) {
    getSapDocumentDAO().save(finishedTiredDocument);
    }
    2) Spring

    <context:annotation-config/>
    <context:component-scan base-package="com.goodyear.emea.gicl.esb.service.impl"/>
    <tx:annotation-driven transaction-manager="txManager" mode="aspectj"/>

    <!-- Get Transaction Manager from OSGI Services -->
    <osgi:reference id="txManager" interface="org.springframework.transaction.Platfor mTransactionManager" />

    <!-- Get DAO from OSGI Services -->
    <osgi:reference id="sapDocumentDAO" interface="com.goodyear.emea.gicl.esb.persistence. SapDocumentDAO" />

    <!-- Expose Persistence as a Service -->
    <osgi:service ref="sapService" interface="com.goodyear.emea.gicl.esb.service.Pers istence" />

    </beans>
    B. Bundle DAO

    1) Class DAO

    @Repository("sapDocumentDAO")
    public class SapDocumentDAOImpl implements SapDocumentDAO {

    private EntityManager em;

    @PersistenceContext
    public void setEntityManager(EntityManager em) {
    this.em = em;
    }


    public SapDocumentDAOImpl() {
    // System.out.println(">>> SapDocumentDAOImpl instantiated");
    }

    public void save(FinishedTireDocument finishedTiredDocument) {
    2) Spring

    <context:annotation-config />
    <context:component-scan base-package="com.goodyear.emea.gicl.esb.persistence.im pl"/>

    <bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
    <bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>

    <!-- Can be used with a DataSource -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitName" value="sap" />
    <property name="jpaVendorAdapter" ref="jpaAdapter" />
    <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- DataSource -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="username" value="sap"/>
    <property name="password" value="sap"/>
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/sapdb"/>
    </bean>

    <!-- EclipseLink adapter -->
    <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseL inkJpaVendorAdapter">
    <property name="databasePlatform" value="org.eclipse.persistence.platform.database.M ySQLPlatform" />
    <property name="database" value="MYSQL" />
    </bean>

    <!-- Expose DAO as OSGI service -->
    <osgi:service ref="sapDocumentDAO" interface="com.goodyear.emea.gicl.esb.persistence. SapDocumentDAO"/>

    <!-- TransactionManager is required -->
    <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- Expose TxManager/Template as OSGI Service -->
    <osgi:service ref="txManager" interface="org.springframework.transaction.Platfor mTransactionManager"/>

    </beans>
    Kind regards,

    Charles
Working...
X