aspose file tools*
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to include LDAP updates and database access in one transaction?