aspose file tools
The moose likes Object Relational Mapping and the fly likes starting new hibernate project; should we use annotation or XML? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "starting new hibernate project; should we use annotation or XML?" Watch "starting new hibernate project; should we use annotation or XML?" New topic
Author

starting new hibernate project; should we use annotation or XML?

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi there,

We are about to start a new project with hibernate. I wonder if it's a good practice to use annotation in our pojos or should we use the XML configuration. I know that most projects were done with XML so I wonder if there are any limitations with annotations.

Thank you!



Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Just two methods of doing the same thing. Personal preference is all that should differentiate.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

Paul is correct, the annotations and XML files provide the same core functionality.

IMHO, annotations are easier to work with and easier to manage. I hate how XML files, in most IDEs, don't integrate with design time checking, so errors don't show up until runtime, which is always a pain to debug. With annotations, you get the benefit of the compiler checking your syntax as soon as you save your code, which I think significantly increased production. That's one thing I always hated about Spring - all this XML that isn't checked at design time.

Of course, this does mean lots of annotations sprinkled across many different classes. In big projects, there is something to be said about having one, single, configuration file where all of your mappings reside.

So, I guess I have two opinions on the subject, both of which I feel strongly about.

-Cameron McKenzie


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Thank you both for your input!
Rohit Mehta
Ranch Hand

Joined: Mar 11, 2005
Posts: 77

Thanks Cameron - I put an end to search for answer of that question (xml/Annotations) with your reply :-)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: starting new hibernate project; should we use annotation or XML?
 
Similar Threads
@ManyToOne - extra column?
Hibernate generate timestamp on create and update
Hibernate Repeated column mapping problem
Problem whne used custom squence name in JPA (hibernate) annotations
Hibernate exception problem