XDoclet: Attribute-Oriented Programming - Best Practices

##### XDoclet

- Overview
- News and Status
- Download/Installation
- Using XDoclet
- Best Practices
- FAQ
- License

##### Ant Task Reference

- <doclet .. />
- <ejbdoclet .. />
- <hibernatedoclet .. />
- <jdodoclet .. />
- <jmxdoclet .. />
- <mockdoclet .. />
- <portletdoclet .. />
- <springdoclet .. />
- <tapestrydoclet .. />
- <webdoclet .. />
- <wseedoclet .. />

##### Tag Reference

- apache (@soap @struts @axis @tapestry)
- bea (@weblogic)
- borland (@bes)
- caucho (@resin)
- ejb (@ejb @dao)
- exolab (@castor)
- hp (@hpas)
- hibernate (@hibernate)
- ibm (@websphere)
- java (@javabean)
- jboss (@jboss)
- jdo (@jdo)
- jmx (@jmx)
- jsf (@jsf)
- macromedia (@jrun)
- mockobjects (@mock)
- mvcsoft (@mvcsoft)
- mx4j (@mx4j)
- objectweb (@jonas)
- oracle (@oc4j)
- orion (@orion)
- portlet (@portlet)
- pramati (@pramati)
- spring (@spring)
- sun (@sunone)
- sybase (@easerver)
- tjdo (@tjdo)
- web (@web @jsp)
- webwork (@webwork)
- wsee (@wsee)
- xdoclet (@xdoclet @doc @msg)

##### Feature Documentation

- Using Value Objects
- EJB Environment Handling

##### Advanced

- Maven Plug-in
- Merge Points
- IDE Integration
- Migration from EJBDoclet
- Ant 1.5 Troubleshooting

##### Community

- Feedback
- Resources
- Tools

##### Development

- Developer Guide
- Javadoc (API)
- Template Language (*.xdt)
- XJavaDoc Site

##### Search XDoclet

##### Project Documentation

- About XDoclet
- Project Info
- Project Reports
- Development Process

## 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.

### Session Beans Best Practices

- Use the Session Facade pattern for safer data management.