This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes how to include LDAP updates and database access in one transaction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to include LDAP updates and database access in one transaction?" Watch "how to include LDAP updates and database access in one transaction?" New topic
Author

how to include LDAP updates and database access in one transaction?

Robert Strong
Ranch Hand

Joined: Sep 10, 2002
Posts: 84
hi,

I'm using BEA Weblogic8.1, I'm coding a Stateless Session Bean, used for Signup, there a user's account should be created in both LDAP and Oracle Database. XA JDBC driver used, with <trans-attribute>Required</trans-attribute> specified in ejb-jar.xml.

if that account already exists in database table, the transaction would rollback, but an entry still created in LDAP. so, it seems LDAP operations and database access cannot be grouped into one distributed transaction?

my code is like below:
try{
ht.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
ht.put(Context.PROVIDER_URL, "ldap://tiger:7001");
ht.put(Context.SECURITY_AUTHENTICATION, "simple");
ht.put(Context.SECURITY_PRINCIPAL, "cn=Admin");
ht.put(Context.SECURITY_CREDENTIALS, "xxxxx");
dirCtx = new InitialDirContext(ht);

Attributes attrNew = new BasicAttributes(true);
Attribute oc = new BasicAttribute("objectclass");
Attribute ouSet = new BasicAttribute("ou");

oc.add("top");
oc.add("person");
oc.add("organizationalPerson");
oc.add("inetOrgPerson");
oc.add("wlsUser");
attrNew.put(oc);
ouSet.add("people");

attrNew.put("wlsMemberOf", "cn=bigrez_staffs,ou=groups,ou=myrealm,dc=bigrezdomain");
attrNew.put("sn", staffVO.getName());
attrNew.put("uid", staffVO.getEmail());
attrNew.put("cn", staffVO.getEmail());
String pwd = "test";
attrNew.put("userpassword", pwd.getBytes());

///add new entry
dirCtx.createSubcontext("cn=" + staffVO.getEmail() + ",ou=people,ou=myrealm,dc=bigrezdomain", attrNew);


StaffEntityHomeLocal staffEntityHomeLocal = (StaffEntityHomeLocal)Locator.getHome("StaffEntity");
staffEntityHomeLocal.create(staffVO);

}
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
There's no such thing as transactions in the LDAP world, so you're pretty much on your own here. E.g. you could try creating the entity bean first and then only create the LDAP entry if the previous operation was successful.


Admit nothing. Blame everyone. Be bitter.
 
 
subject: how to include LDAP updates and database access in one transaction?
 
Similar Threads
Simple Add using JNDI
LDAP: Add Users
failed to retrieve attributes from weblogic embeded ldap
com.sun.net.ssl.internal.ssl.Provider()
JBOSS LdapLoginModule authentication. Help needed for code to use LoginContext