为什么我们使用Hibernate注解? [英] Why do we use hibernate annotation?

查看:188
本文介绍了为什么我们使用Hibernate注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么很重要?根据XML映射有哪些优势呢?你能explan这些?谢谢你。

Why is it important? what are advantage according to XML mapping? Can you explan these? thank you.

推荐答案

这是不是在强制的重要。这是一个不同的可能性,以实力和弱点。

It is not something important as in "mandatory". It's a different possibility, with strength and weaknesses.

优点:


  • 编译时检查:用Java编写(而不是XML)是非常人性化的IDE时下。 没有更多的错字开始发现你的应用程序(增量编译),没有太大时要记住(完成)...

  • 本地化与code(类级别),而不必打开两个文件(Java和XML)来获得完整的故事,有一个注释的Java文件,您只打开一个文件。这是少重复,在长期运行得更快。

  • 本地化与code(方法或字段级):因为注释上的一个方法(或域)去了,还有的无需指定方法它属于。该redondant信息没有给出,这是短,并且总是相干(即使是code重构例如之后)。维护是如此之快。

  • 工具(javadoc中,使用反射其他工具)可以使用注解一些其他要求。

  • 注解比XML更新,团队使用他们的时候收到了提供的更好的默认值输入。 XML有一些,但也没有太大变化兼容性的原因。通常情况下,使用注解技术,您没有写批注可言,和它的作品。试想一下,省时省力,特别是在开发过程中。

  • Compile-time checking : writing in Java (instead of Xml) is very user-friendly in the IDE nowadays. No more typos discovered when starting your application (incremental compilation), not that much to remember (completion)...
  • Localized with the code (class level) : instead of having to open two files (java and xml) to get the full story, with one annotated java file, you open only one file. This is less repetitive, faster in the long run.
  • Localized with the code (method or field level) : because the annotation go on a method (or field), there is no need to specify the method it belongs to. That redondant information is not given, which is shorter, and always coherent (even after a code refactoring for example). Maintenance is so much faster.
  • Tools (javadoc, other tools using reflection) can use the annotations for some other requirements.
  • Annotations are newer than the xml, the team used the input they had received at the time to provide better default values. Xml has some, but can't change much for compatibility reasons. Often, with the annotations technology, you write no annotation at all, and it works. Imagine the time-saving, especially during development.

这篇关于为什么我们使用Hibernate注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆