As I started working with Hibernate a few days ago, I was just wondering : suppose you're starting a project from scratch. Would you use annotation-based mapping or Hibernate mapping files, to generate the database schema.
It is my understanding that Hibernate mapping files offer some features that you won't find (at least, not the exact equivalent) with annotations. But still, I have the feeling that nowadays, projects using Hibernate would rather go for annotation-based than Hibernate mapping files.
Has anybody ever chosen mapping files over annotations, and if so, for what reasons?
What advantages I see in using @Annotations:
What advantages I see in using XML:
We use annotations, but keep XML as an option.
Go ahead with annotations any day. The XML configurations where really over used and saving the metadata inside the class is a good viable option.
Annotations will help you map the relationships better and it will align you to the JPA standard as hibernate uses mostly JPA annotations. There are no real problems using annotations and there is not much trade-off either. It has superior advantages over the XML based configurations. There might be few hacks missing when you use annotations but they will come along.
It is even possible to use annotations for new classes in a legacy project that has XML based mapping as told here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With