I have seen many tutorials in which hibernation is implemented using annotations (mostly hibernation annotations or JPA annotations). There is a tutorial mainly about using hibernate configuration files (hbm.xml files). Using annotations is not used at all.
Now I'm a little confused, which one is better suited?
I definitely prefer to use annotations to define display metadata. And in fact, annotations are an approach recommended by Hibernate developers. Quoting Gavin King in More XML Than Code?
Of course, Hibernate Annotations has existed since the beginning of 2005, and there is no reason for people to define mappings in XML.
Pros:
Minuses:
In other words, use annotations if you can. If you cannot (you cannot change the code, for example, when working with legacy code), use XML mappings.
! , . , .. Hibernate , . Entity Java.
, XML . Java 5, , XML, , . , Spring 3.x framework Java EE 6 .
Spring 3.x
Java EE 6
. , , , , . persistence.xml, , . .
, . , , : java.