This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Annotation Vs XML Configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Annotation Vs XML Configuration" Watch "Annotation Vs XML Configuration" New topic
Author

Annotation Vs XML Configuration

s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Hi All,

I have never worked on Projects that used Annotations. and I was wondering why EJB3 is based on annotation approach.

I feel that with all services like transaction, security etc.., embedded into the code through annotations, if something has to be changed, we need to update code and look for all dependant methods/code that has to be changed. It would be a maintenance nightmare if there is huge such code which developer has to scan through to make all these changes.

Having Configuration in XML would save sometime to change on file instead of so many files.

Ofcourse regression testing is crucial in both the cases.

What adavantages you see in using Annotation approach?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Actually, you can use both in EJB3.

Use annotation for the defualt values, and then if you need to have something different in your deployment you can create a configuration file that overwrites what is in the annotation.

The plus about annotations is that it keeps that information close to the code where you tend to ask what the transaction level is, when you are looking at the code. Rather than having to go somewhere else to see what it is.

I also find configuration files are getting rampant and then become a maintenance issue.

But the keyword is flexibility.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bernhard Neuhauser
Greenhorn

Joined: Feb 06, 2006
Posts: 21
I think the main advantage of the annotation aproach is, that it avoids redundancy.

The annotation is tightly connected to the class / method / attribute. As such when you refactor an attribute name you cant forget to change the string inside the mapping file, because there is none.

But mostly its a must have to be able to overwrite attributes in xml files, to give deployers the possibility to change minor aspects without the need of recompilation. (Maybe he just wants to change table names)

Search for jibx vs. jaxb discussions. The jibx developers always highlight the possibility to maintain differend mappings. A pure annotation aproach cant do that (i think). The benefit is that its possible to migrate to a new xml file without changing the pojos. This offers the ability to an easier migration path, because the same pojos will be able to handle the old and also the new xml format.

But im not sure if there is need for such an issue concerning ejb, because one cmp will only handle one mapping per deployed instance. So there is no need for the same migration issues (maybe im wrong).

hth
cybi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Annotation Vs XML Configuration
 
Similar Threads
[Ask] What kinds of Hibernate do you use?
spring in action - annotations
why the annotaion way
Hibernate Search without Annontation
Annotation or XML mapping