Announcement Announcement Module
No announcement yet.
LDAP Transactions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I would presume your problem was because you were using BeanFactory instead of ApplicationContext. It's quite a common problem people have with AOP and is discussed at the beginning of the reference manual.
    Last edited by karldmoore; Aug 29th, 2007, 10:25 AM.


    • #17
      Thanks a lot for all of you, I modify my code, and I had an org.springframework.beans.factory.BeanCreationExce ption:

      Resource resource = new ClassPathResource("testContext.xml");
      //BeanFactory factory = new XmlBeanFactory(resource);
      ApplicationContext context = new ClassPathXmlApplicationContext(
                  new String[] {"testContext.xml"});
      BeanFactory factory = (BeanFactory) context;
      PerfilDao ldapContact = (PerfilDaoImpl)factory.getBean("myDataAccessObjectTarget");
      and my configuration:

         <bean id="transactionManager" 
            <constructor-arg ref="contextSource" />
         <bean id="myDataAccessObjectTarget" class="PerfilDaoImpl">
            <property name="ldapTemplate" ref="ldapTemplate" />
      	<bean id="myDataAccessObject"
      		<property name="transactionManager" ref="transactionManager" />
      		<property name="target" ref="myDataAccessObjectTarget" />
         		<property name="transactionAttributes">
      				<prop key="create">PROPAGATION_SUPPORTS</prop>
      				<prop key="delete">PROPAGATION_SUPPORTS</prop>
      				<prop key="update">PROPAGATION_SUPPORTS</prop>
      				<prop key="getAllPerfilCuentas">PROPAGATION_REQUIRED,readOnly</prop>


      • #18
        How about this?
        ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
        PerfilDao ldapContact = (PerfilDao) context.getBean("myDataAccessObject");
        Last edited by karldmoore; Aug 29th, 2007, 10:24 AM.


        • #19
          A couple of other things I've noticed. Your transaction propagation setting means if an existing transaction doesn't exist it's going to execute non-transactionally. It would also be really useful to see the code you are running to test this.

          Last edited by karldmoore; Aug 29th, 2007, 10:24 AM.


          • #20
            Hi Karldmoore, I'm going to try it.
            But I changed to programatically manner using the ContextSourceTransactionManager class to perform a transaction LDAP, I saw the forum and and others forums, tutoriales and I see that almost samples are the same, but I have some problems to do the transaction programmatic, here some code:

            LdapContextSource ldapContextSource = new LdapContextSource();
            TransactionAwareContextSourceProxy tacsp = null;
            final Perfil p1 = new Perfil();
            //construct an appropriate transaction manager 
            ContextSourceTransactionManager txManager = new ContextSourceTransactionManager();
            DefaultTransactionDefinition def = new DefaultTransactionDefinition();
            //explicitly setting the transaction name is something that can only be done programmatically
            Assert.notNull(txManager, "The 'transactionManager' argument must not be null.");
            tacsp = new TransactionAwareContextSourceProxy(ldapContextSource);
            final ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
            final PerfilDao ldapContact = (PerfilDao)context.getBean("myDataAccessObject");
            //Asignación de los valores de un perfil
            p1.setCn("Alexis Moreno");
            p1.setMail("[email protected]");
            // execute your business logic here
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            			protected void doInTransactionWithoutResult(TransactionStatus status) {
            			ldapContact.create(p1, "perfilTelmex");
            			catch(Exception e){
            Where is/are my error(s)?



            • #21
              I forgot to said that I catch and Exception in the line "transactionTemplate.execute(new TransactionCallbackWithoutResult() {":

              Exception in thread "main" java.lang.NullPointerException
              at ource.getAnonymousEnv(
              at extSource.getAuthenticatedEnv(AbstractContextSourc
              at extSource.getReadOnlyContext(AbstractContextSource .java:102)
              at org.springframework.ldap.transaction.compensating. tNewHolder(ContextSourceTransactionManagerDelegate .java:79)
              at org.springframework.transaction.compensating.suppo rt.AbstractCompensatingTransactionManagerDelegate. doBegin(AbstractCompensatingTransactionManagerDele
              at org.springframework.ldap.transaction.compensating. manager.ContextSourceTransactionManager.doBegin(Co
              at atformTransactionManager.getTransaction(AbstractPl
              at nTemplate.execute(
              at SimpleService3.<init>(
              at SimpleService3.main(


              • #22
                Debugging I saw the exception "java.lang.IllegalArgumentException: Key must not be null" for the LdapContextSource object
                Last edited by sacara; Jul 9th, 2007, 04:30 PM.


                • #23
                  When creating a ContextSource programmatically you need to call afterPropertiesSet once you're done setting the properties. That might account for the IllegalArgumentException.


                  • #24
                    Ok, I already modified my class, and now I have problems with my xml. I put a piece of code of my xml before. I hope somebody could give me a favor to tell me my mistakes, I'm new with LDAP transactions.


                    • #25
                      It's really difficult to follow what you're doing. First you're using XML configuration, then you switch to code, and then you switch back to XML. Please be consistent, post any stack traces you get, and explain carefully what you did and what went wrong. You can't just say "and now I have problems with my xml" and expect an answer.

                      Are you using LDAP transactions together with JDBC? You haven't said so explicitly, but it seems that's what you want to do. Am I right?

                      Did you change the transaction propagation settings as Karl suggested? What happened?

                      Where is the test code that Karl asked for? How do you know that it doesn't work?


                      • #26
                        Hi Ulsa, I'm going to describe what I'm doing.
                        I need to use transaction for LDAP now (after a time, I'm going to incorporate JDBC transactions, so in the future I'm going to have two transactions: LDAP and JDBC), I chose the programmatic manner to do transactions for LDAP, and I'm trying to use the TransactionTemplate and PlatformTransactionManager classes following the examples in, but I didn't see how has to be my xml configuration. Before to use the TransactionTemplete and PlatformTransactionManager, I tried to use the ContextSourceTransactionManager and ContextSourceAndDataSourceTransactionManager class but I saw that I had the same problem with my xml configuration, because I think that I mixed the programmatic and declarative manner, and I don't know how has to be my xml configuration for programmatic manner. I know that my xml configuration is wrong because I get exceptions.
                        What class have I to use to do a transaction manager object? To use a TransactionTemplate object is similar or equivalent to use a ContextSourceTransactionManager or ContextSourceAndDataSourceTransactionManager object? and What changes have I to do in my xml configuration for the programmatic manner?

                        When I used the ContextSourceTransactionManager class for PlatformTransactionManager, I did the follow manner:

                        ContextSourceTransactionManager txManager = (ContextSourceTransactionManager)context.getBean("myDataAccessObject");
                        and, for the TransactionTemplate class:

                        TransactionTemplate tt = (TransactionTemplate)context.getBean("contextSourceTarget");
                        I don't know if is correct use "getBean", I assume that is the manner for get the context of xml and initialize the transaction object.

                        I hope that was understandable my explanation, thank you
                        Last edited by sacara; Jul 11th, 2007, 11:51 AM.


                        • #27
                          Did your problem got resolved?

                          Hi Sacara, Did your problem got resolved? I am facing the same issue of not getting rollback when using Spring LDAP Transactions Declaratively. I compared my XML file when you are using the org.springframework.ldap.transaction.compensating. manager.ContextSourceTransactionManager and i am using PROPAGATION_REQUIRES_NEW. The transaction is not getting rolledback.

                          Can anybody help?


                          • #28
                            Is it a conscious choice of having PROPAGATION_REQUIRES_NEW? As Jürgen explains in this post, this transaction definition creates an independent inner transaction, which will be committed or rolled back completely independent of the outer transaction. It's mainly used for manual id generation inside a longer transaction. Is this really what you want?


                            • #29
                              Also, I suggest you create a new thread for this particular problem. This thread is now three pages long.

                              As always, post your configuration (the XML), the bootstrapping code (the one that reads the XML), and the actual code (that uses the beans). Use the [code] tag.


                              • #30
                                It seems i can't start a new thread with the below reply

                                Hi Ulsa,

                                Thanks a lot for your reply. Yes I understood by debugging the code during my trace back to see where exactly it is failing. I can post the location of the Spring code where exactly is failing, but donno the reason where I am going wrong in the settings. First please watch my files below:


                                <bean id="contextSourceTarget" class=" ontextSource">

                                <property name="xxx" value="xxx" />
                                <property name="base" value="ou=system" />
                                <property name="userName" value="uid=xx,ou=xx" />
                                <property name="password" value="xx" />
                                <bean id="contextSource" class="org.springframework.ldap.transaction.compen sating.manager.TransactionAwareContextSourceProxy" >
                                <constructor-arg ref="contextSourceTarget" />
                                <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
                                <constructor-arg ref="contextSource" />
                                <bean id="transactionManager" class="org.springframework.ldap.transaction.compen sating.manager.ContextSourceTransactionManager">
                                <property name="contextSource" ref="contextSource"/>

                                <bean id="myDataAccessObjectTarget" class=" .AdminSecurityServiceImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />

                                <bean id="myDataAccessObject"
                                class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
                                <property name="transactionManager" ref="transactionManager" />
                                <property name="target" ref="myDataAccessObjectTarget" />
                                <property name="transactionAttributes">
                                <prop key="save*">PROPAGATION_REQUIRES_NEW,-AdminSecurityServiceException</prop>

                                <bean id="userDAOLdap" class="com.xx.persistence.adminsecurity.impl.UserD AOLdapImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />
                                <bean id="userGroupDAOLdap" class="com.xx.persistence.adminsecurity.impl.UserG roupDAOLdapImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />

                                The code inside the save method which is called and the point where the exception is simulated.

                                try {

                                Resource resource = new ClassPathResource("springconfig.xml");
                                factory = new XmlBeanFactory(resource);
                                ldapUserDAO = (UserDAOLdapImpl) factory.getBean("userDAOLdap");
                                ldapUserGroupDAO = (UserGroupDAOLdapImpl) factory

                                if (userGroups != null) {
                                Iterator iter = userGroups.iterator();
                                while (iter.hasNext()) {
                                UserGroup userGroup = (UserGroup);
                                if(StringUtils.isEmpty(userGroup.getCommonName())) {
                                userGroup.setErrorMessage("Error: User Group Common Name is mandatory.");

                                throw new AdminSecurityServiceException();

                                } catch (Exception ee){}

                                public UserGroup addUserGroup(UserGroup userGroup) {

                                Name dn = AdminSecurityUtil.buildUserGroupDn(userGroup);
                                DirContextOperations context = null;

                                try {
                                context = ldapTemplate.lookupContext(dn);
                                } catch (NameNotFoundException e) {
                                context = new DirContextAdapter();
                                ldapTemplate.bind(dn, context, null);
                                return userGroup;
                                return userGroup;

                                Location in the Spring Code where it is failing to Rollback.

                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(Native
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(Native
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at java.lang.reflect.Method.invoke(
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at npointUsingReflection(
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at $Proxy0.saveUserGroupChanges(Unknown Source)

                                I am also getting a info message below:
                                [8/26/08 9:08:03:130 EDT] 0000000d TimeoutManage I WTRN0006W: Transaction 0000011BFF1EF2EB000000010000000129960A503C631343F5 4A37DA4DCA3ED5AAD6D8490000011BFF1EF2EB000000010000 000129960A503C631343F54A37DA4DCA3ED5AAD6D849000000 01 has timed out after 120 seconds.

                                Please help.....