Migrate enterprise bean code from V1.0 to V1.1
The following information generally applies to any enterprise bean that currently complies with V1.0 of the EJB specification.
Overview
For more information about migrating code for beans produced with Rational Application Developer, see the documentation for that product. For more information about migrating code in general, see "Resources for learning."
Procedure
- In session beans, replace all uses of javax.jts.UserTransaction with javax.transaction.UserTransaction. Entity beans may no longer use the UserTransaction interface at all.
- In finder methods for entity beans, include FinderException in the throws clause.
- Remove throws of java.rmi.RemoteException; throw javax.ejb.EJBException instead. However, continue to include RemoteException in the throws clause of home and remote interfaces as required by the use of Remote Method Invocation (RMI).
- Remove uses of the finalize() method.
- Replace calls to getCallerIdentity() with calls to getCallerPrincipal(). The use of getCallerIdentity() is deprecated.
- Replace calls to isCallerInRole(Identity) with calls to isCallerinRole (String). The use of isCallerInRole(Identity) and java.security.Identity is deprecated.
- Replace calls to getEnvironment() in favor of JNDI lookup. As an example, change the following code:
String homeName = aLink.getEntityContext().getEnvironment().getProperty("TARGET_HOME_NAME"); if (homeName == null) homeName = "TARGET_HOME_NAME";The updated code would look something like the following:Context env = (Context)(new InitialContext()).lookup("java:comp/env"); String homeName = (String)env.lookup("ejb10-properties/TARGET_HOME_NAME");
- In ejbCreate methods for an entity bean with container-managed persistence (CMP), return the bean's primary key class instead of void.
- Add the getHomeHandle() method to home interfaces.
public javax.ejb.HomeHandle getHomeHandle() {return null;}
What to do next
Consider enhancements to match the following changes in the specification:
- Primary keys for entity beans can be of type java.lang.String.
- Finder methods for entity beans return java.util.Collection.
- Check the format of any JNDI names being used. Local name spaces are also supported.
- Security is defined by role, and isolation levels are defined at the method level rather than at the bean level.
Task overview: Using enterprise beans in applications
Related Reference
Enterprise beans: Resources for learning