Sleep using annotations or using sleep configuration files

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?

+5
source share
4 answers

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:

  • annotations are usually less detailed
  • annotations live with code, easier to maintain (IMO)

Minuses:

  • Changing metadata requires recompilation (if this is really a problem)

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.

+8
source

! , . , .. Hibernate , . Entity Java.

, XML . Java 5, , XML, , . , Spring 3.x framework Java EE 6 .

+1

. , , , , . persistence.xml, , . .

0

, . , , : java.

0

All Articles