I have seen many tutorials where the hibernate is implemented using annotations (basically hibernate annotations or JPA annotations). There are tutorial which mainly focuses on using the hibernate configuration files(hbm.xml files). No use of annotations at all.
Now I am little bit confused, which one is better approach ?
I definitely prefer to use annotations to define my mapping metadata. And actually, annotations are the approach recommend by Hibernate developers. Quoting Gavin King in More XML than code?
Pros:
Cons:
In other words, use annotations if you can. If you can’t (you can’t change the code, for example when working with legacy code), use XML mappings.