Home

Post

Feeds

RSS

Aug 15Hibernate: Annotations or XML Mapping?

Until recently, I've always used the XML mapping files to define my persistence model with Hibernate. I was not real keen on the idea of using meta to define persistence in the objects themselves via annotations. However, I decided to give it a shot recently. My main argument had always been that by using the XML mapping, my persistent objects are not tied to Hibernate, exclusively. When I stopped to think about it though, one thought really hit me hard: I don't use any other ORM for my Java code. Why would it matter if the meta for mappings is in the code?

This being said, I wanted to pose a question: Is there a benefit to using annotations over XML mapping (other than JVM compatibility)? Your thoughts in the comments, please.

Posted by: Andrew Powell

Categories: Java , ColdFusion , Spring , Universal Mind , Hibernate , XML

Comments

I'll be interested to see what people say on this question. Joe has been building Hibernate-based Groovy code using XML but I've started using annotations instead on the grounds that we aren't likely to use anything but Hibernate and it means less files to manage and no synchronization between the bean and the XML file. If there are really good reasons to use XML, I may reconsider.

Sean Corfield Sean Corfield
08/15/08 6:47 PM

Annotations also give you a better path to using pure JPA if you ever decide to go that route. XML doesn't give you that flexibility.

Andy Powell Andy Powell
08/15/08 10:40 PM

annotations mean your pojos are irrevocably bound to hibernate - it may be the only orm tool you ever use, but are your objects ever reused in situations where they wont be persisted? annotations dont belong in code at all imho.

So, which way did you go? I have also always used XML for my mappings and am curious what you decided.

Rich Tretola Rich Tretola
11/29/08 11:40 PM

I ended up going towards annotations because I finally realized that I will never use another ORM. Annotations are cleaner and keep you from having to alter your VO and your mapping file.

Andy Powell Andy Powell
12/01/08 11:10 AM

Write your comment



(it will not be displayed)







About Andrew Powell

More ...

Powered by Mango Blog: a ColdFusion blog engine