• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!



 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just two methods of doing the same thing. Personal preference is all that should differentiate.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for your input!
 
Ranch Hand
Posts: 79
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cameron - I put an end to search for answer of that question (xml/Annotations) with your reply :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic