Since we started our EJB 3.0 implementation, I've written a lot of unit
tests and tutorials for it. Other than actually actually enjoying
writing an EJB for a change, I thought alot about when and where XML
should be used over annotations and in what situations annotations
should probably be used over XML. I came up with these rules:
- Use an annotation if the metadata you are applying changes the design of your class.
- Use an annotation if the metadata changes the design of code interacting with your class.
- If your application needs to be portable between app-servers or
databases, don't use an annotation that will not allow you to be
- Use XML when you want to configure on a per-deployment basis.
Nice overview of when to use annotations, and when to use XML configuration with