Announcement Announcement Module
Collapse
No announcement yet.
tying together jpa and ldap transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tying together jpa and ldap transaction

    Does anyone have any idea how to wire together a jpa transaction with a spring ldap transaction? I see that spring ldap provide the ContextSourceAndDataSourceTransactionManager for wiring my ldap context source and my datasource, but this doesn't seem to apply to jpa. below is part of my app context

    Code:
    ....
    	<bean id="entityManagerFactory"  
    	      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">  
             <property name="persistenceUnitName" value="persistentUnit"/>  
             <property name="dataSource" ref="dataSource" />  
             <property name="jpaVendorAdapter">  
                 <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
                     <property name="database" value="ORACLE"/>  
                     <property name="showSql" value="true" />  
                     <property name="generateDdl" value="false" />  
                 </bean>  
             </property>  
        </bean>  
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
            <property name="url" value="jdbc:oracle:thin:@111.11.11.111:1521/dbschema"/>
            <property name="username" value="username"/>
            <property name="password" value="xxxxxxx"/>       
        </bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    	
    
    	<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="ldap://ldapSvr:139012" />
    <property name="userDn" value="cn=Directory Manager" />
    <property name="password" value="xxxxxx" />
    </bean>
    
    	
    	<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    		<constructor-arg ref="contextSource" />
    	</bean>
    
    
    .....
    any help would be greatly appreciated.

    cheers...

  • #2
    Hi,
    Have you found anything yet?
    I am too looking for solution on how to use JPA and LDAP transaction together.
    With ContextSourceAndDataSourceTransactionManager I get transactions on LDAP but my database changes are not getting committed.

    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.
    Last edited by niravpatel44; Mar 23rd, 2012, 08:35 PM.

    Comment

    Working...
    X