Why do we use sleep annotation?

Why is it important? What is the benefit of XML mapping? Can you explain this? thanks.

+6
xml mapping annotations hibernate
source share
2 answers

This is not something important, as in the "mandatory". This is another opportunity, with strengths and weaknesses.

Benefits:

  • Checking compilation time: writing in Java (instead of Xml) is very convenient in the IDE today. No more typos found at application startup (incremental compilation), not much to remember ( completion ) ...
  • Localized with code (class level): instead of opening two files (java and xml) to get the full story, with one annotated java file, you open only one file . It is less repeatable, faster in the long run.
  • It is localized with code (method or field): because the annotation goes to the method (or field), you do not need to specify the method to which it belongs. This extra information is not indicated, which is shorter and always coherent (even after refactoring the code, for example). Service is much faster.
  • Tools (javadoc, other tools that use reflection) can use annotations for some other requirements.
  • Annotations newer than xml, the team used the input they received at the time to provide better defaults . Xml has some, but cannot change much for compatibility reasons. Often using annotation technology you don’t write annotations, and it works . Imagine saving time, especially during development.
+14
source share

I don’t understand all the hype around annotation, and I prefer HBM for the following reasons (these reasons cancel out such flaws as typos, compile-time checking for me):

  • Relative Concern / Immediate Responsibility: With HBM, you have all ORM-related stuff in HBM. The essence and logic of the domain (regardless of the structure of the table) in the java class. Your DB and java class can be changed independently (only HBM needs to be updated).
  • Your code is not cluttered with annotation. I prefer to just look at the domain logic. Annotations add a lot of noise.

If the HBMs are well organized (one HBM per java class, sequential naming), it becomes easy to navigate between them. The Junit test and some discipline eliminate the need to check compile time. As for defaults, I think that if sleep mode may not work at all with annotations, it should be able to work without XML at all (conceptually - I don’t know if this is a reality)

+2
source share

All Articles