Announcement Announcement Module
Collapse
No announcement yet.
Spring LDAP and JPA transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring LDAP and JPA transactions

    Hi,
    I am looking for solution on how to use JPA and LDAP transaction together.
    I have tried ContextSourceAndDataSourceTransactionManage.r I get transactions on LDAP but my database changes are not getting committed!!

    btw, I have also tried transactionawaredatasourceproxy which didn't work either.
    Here's the fragements of my code:

    application-context:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitName" value="PlatformPU"/>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="true"/>
    <property name="generateDdl" value="false"/>
    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
    </bean>
    </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <!-- jdbc:mysql://[host][,failoverhost...][ort]/[database] [?propertyName1][=propertyValue1][&propertyName2][=propertyValue2] -->
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    </bean>

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

    <!-- ldap and db tx -->
    <bean id="nsrContextSourceTarget" class="org.springframework.ldap.core.support.LdapC ontextSource">
    <property name="url" value="${nsr.ldap.url}"/>
    <property name="base" value="${nsr.ldap.base_dn}"/>
    <property name="userDn" value="${nsr.ldap.login_user_dn}"/>
    <property name="password" value="${nsr.ldap.login_user_password}"/>
    <property name="pooled" value="false"/>
    </bean>

    <bean id="nsrPoolingContextSource" class="org.springframework.ldap.pool.factory.Pooli ngContextSource">
    <property name="contextSource" ref="nsrContextSourceTarget" />
    <property name="dirContextValidator">
    <bean class="org.springframework.ldap.pool.validation.De faultDirContextValidator" />
    </property>
    <property name="testOnBorrow" value="true"/>
    <property name="testWhileIdle" value="true"/>
    </bean>

    <bean id="nsrTxContextSource"
    class="org.springframework.ldap.transaction.compen sating.manager.TransactionAwareContextSourceProxy" >
    <constructor-arg ref="nsrPoolingContextSource" />
    </bean>

    <bean id="nsrTxLdapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
    <constructor-arg ref="nsrTxContextSource"/>
    </bean>

    <bean id="ldapEntityManager" class="com.quova.platform.services.NSRSpringLDAPPr ovider">
    <property name="baseDn" value="${nsr.ldap.base_dn}"/>
    <property name="baseUserDn" value="ou=Users"/>
    <property name="baseGroupDn" value="ou=Groups"/>
    <property name="userObjectCategory" value="${nsr.ldap.user_obj_category}"/>
    <property name="groupObjectCategory" value="${nsr.ldap.group_obj_category}"/>
    <property name="nsrLdapTemplate" ref="nsrLdapTemplate" />
    <property name="nsrTxLdapTemplate" ref="nsrTxLdapTemplate" />
    </bean>

    <bean id="nsrLdapDBTransactionManager" class="org.springframework.ldap.transaction.compen sating.manager.ContextSourceAndDataSourceTransacti onManager" >
    <property name="contextSource" ref="nsrTxContextSource" />
    <property name="dataSource" ref="dataSource"/>
    <qualifier value="LdapAndDbTx"/>
    </bean>

    Java Code:

    @Transactional(readOnly=false, value="LdapAndDbTx", propagation=Propagation.REQUIRED)
    public void createIdentity(QIdentity identity) throws Exception {

    //call LDAP adapter to do ldap bind, lookup etc

    // call DAOMethod(record) to persist.

    }

    Class DaoImpl{

    private EntityManager entityManager;

    @PersistenceContext(unitName="PlatformPU")
    public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
    }

    DAOMethod(Record record) {

    entityManager.persist(record);
    }

    So, I am wondering that this entitymanager I am using has a different copy of datasoruce or underlaying connection which differs from ContextSourceAndDataSourceTransactionManager connection. Hence my db transaction never gets commited.

    Do I need to use Jtatransactionmanager?

  • #2
    watch out ContextSourceAndJpaTransactionManager answer at stackoverflow

    Comment

    Working...
    X