Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have seen many questions but all of their solution still not clear. here is my set up my Spring Context file

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    ..
    ...


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    ...
    ...

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="entityManagerFactory1"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        autowire="byName">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="packagesToScan" value="com.my.dom.domain" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle10gDialect
                </prop>             
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.jdbc.fetch_size">50</prop>
                <prop key="hibernate.jdbc.batch_size">10</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="persistenceUnitName" value="PersistenceUnit1"></property>
    </bean>

    <bean id="EntityManagerFactory2"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        autowire="byName">
        <property name="dataSource" ref="myDataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="packagesToScan" value="com.my.dom.domain" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.H2Dialect
                </prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.jdbc.fetch_size">50</prop>
                <prop key="hibernate.jdbc.batch_size">10</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
     ..
     ...     


    <bean id="entityManager1" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory1" />
    </bean>
    <tx:annotation-driven transaction-manager="entityManager1" />

    <bean id="EntityManager2" factory-bean="EntityManagerFactory2" factory-method="createEntityManager" autowire="byName" scope="prototype"/>
    <tx:annotation-driven transaction-manager="EntityManager2" />


    <context:component-scan base-package="com.my.dom" />

    <jpa:repositories base-package="com.my.dom.repository"
        entity-manager-factory-ref="entityManagerFactory"
        transaction-manager-ref="transactionManager" />

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>


</beans>

All data source and other connection beans are in place and working fine.

My DAO code is as follows package com.my.dom.dao;

@Component
public class MyDAOImpl implements MyDAO {

@PersistenceContext(unitName="PersistenceUnit1")
EntityManager entityManager; // this is IAR EntityManager.

@Override
@Transactional
public boolean saveMyGroups(
        List<MyGroups> theGroups) {

    logger.info("Entering method -  saveFuturetheGroups ");
    //entityManager.getTransaction().begin();
    for(MyGroups pg : theGroups){
        MyGroups attachedENtity = entityManager.merge(pg);
        entityManager.persist(pg);
    }
    //entityManager.getTransaction().commit();
    entityManager.flush();
    logger.info("Exiting method -  saveFuturetheGroups ");
    //List<MyGroups> savedEntities = futureProcGrpRepository.save(theGroups);
    return true;
}

}

I have all the cglib and aopalliance1.0.jars in classpath as suggested in Spring+JPA @Transactional not committing

Still my code is not committing the changes to DB. ANy help pointers will be really helpful.

The code shows select and insert sql statements and no exceptions throws but code doesnt commit. Is there any issues in @Transactional annotation?

Can defining multiple entitymanagers be any issues here?

share|improve this question
Presume that your Entity class is not defined as insert=false,update=false etc – Polppan 9 mins ago

1 Answer

you are to specifiy your transaction manager on your code

@Transactional("entityManager1")
public boolean saveMyGroups(
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.