Best Practices

This document contains best practices when using XDoclet. Note that these are the opinions of the XDoclet team only, so they could be biased.

Caching the home interface

Add the cacheHomes="true" parameter to the <utilobject/> task to have the utility objects cache the homes (you no longer need an EJBHomeFactory!):

<utilobject cacheHomes="true"/>

Examples how to lookup the home interface using the utility object (it will narrow if needed, and uses the COMP name or JNDI name):

EmployeeManager employeeManager = EmployeeManagerUtil.getHome().create();
Properties jndiEnvProps = ... ;
CompanyHome companyHome = CompanyUtil.getLocalHome(jndiEnvProps);

GUID Generator

Need an extremely reliable key generator? Add the includeGUID="true" parameter to the <utilobject/> task to have a key generator that features:

  • unique to the millisecond
  • unique to the server IP address
  • unique to the object hashcode
  • unique to a SecureRandom
  • String, 32 chars
  • very performant
  • EJB 2.0 spec compliant

<utilobject includeGUID="true"/>

To generate a unique key:

String id = SomeBeanUtil.generateGUID(this);

Use a dot to seperate namespace and element

To avoid getting Sun JavaDoc (JDK 1.4) warnings about unknown tags ("warning - @ejb:interface-method is an unknown tag"), replace the : with a . (JavaDoc will ignore these tags).

Entity Beans Best Practices

  • Try to avoid compound primary keys.
  • Always set the Value Object in ejbPostCreate(..), so that CMR fields are assigned correctly.