• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotations vs XML

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I'm finding it a bit hard using Annotations for EJB 3 entities than using plain XML. How many accep the same?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But they look very similar. What do you find hard to use with annotations ?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm actually preparing for my SCBCD 5 certification and as I read from the EJB 3 in Action book, I find that I need to remember a lot of these Annotations for Entities compared to MDB's or Session beans.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true. But if you know the XML, annotations should be straight-forward as the syntax is pretty similar, isn't it ?
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way,
are there questions about the XML syntax at the exam ?
I have read mixed reports on that matter, some say there aren't any question about XML, only annotations, and others say both are included.

What do you say ?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christophe Verre:
That's true. But if you know the XML, annotations should be straight-forward as the syntax is pretty similar, isn't it ?


Christophe I agree with your point. I have another question to ask here. How is it when it comes to the choice of using Annotations or XML fiels for mapping? Which one has advantages over the other and what would they be? Any idea?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one has advantages over the other and what would they be?

I think it depends on people. Some like annotations, some prefer XML. People used to EJB2.x might still stick to XML.
The cool thing is that, in the end, the XML overrides the annotations so even if annotations are used, there's still a way to override them. Apart from that, I don't see any obvious advantage which would not break into a war between annotation-lovers and xml-lovers
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Vote for Annotations over XML.
They are self explanatory and easy to use. Later, if anyone wants to debug the code, we can understand very easily about a method by looking into its annotations.
I would rather feel happy if the XML declarations will be removed from EJB in next version so that I needn't have to read them
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But using Annotations for Entity mapping becomes hard at some times. Don't they? Imagine you are maintaining a EJB 3 app and what would you like to see? I guess I'd prefer XML.

Another question that I have is as mentioned in one of the posts above, does the exam test us also on XML DD's? Any suggestion from previous exam takers?
 
S Bhanage
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just to inform you that :

- Annotations are hard coded parameters.
- Xml elements are run time parameters and can override annotations except
1) Ejb Bean type
2) Transaction Attribute type
and might be few more which i dont remember right now.


Use of Xml elements increases ejb-jar.xml length
and not very readable.

Use of excessive annotations also causes issues for readability
as it becomes tedious to keep track of all annotations when you have
more beans in your application.

So best technique is to have moderate use of annotations as well as Xml elements.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic