本文介绍了为什么人们继续使用XML映射文件,而不是注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的人仍在积极使用,而不是注释XML文件来指定自己的ORM(休眠/ JPA)映射观察到的奇怪的事实(基于休眠标签中的问题)。

I've observed the strange fact (based on the questions in the hibernate tag) that people are still actively using xml files instead of annotations to specify their ORM (Hibernate/JPA) mappings.

有少数情况下,其中,这是必要的:

There are a few cases, where this is necessary:


  • 您正在使用提供的类,并且要映射它们。

  • 您正在编写一个API,它的域类可以在没有JPA的供应商使用,所以你不希望强制JPA / Hibernate的依赖。

但这些都不是常见的情况,我想。

But these are not common cases, I think.

我的假设是:


  • 人习惯把XML文件和不舒服/不想打扰学习使用注解方法。

  • 的Java pre-1.5在该项目被迫并没有什么办才好

  • 人不知道,注释是一个全功能的替代XML映射。

  • 遗留系统的支持,从而改变了做法被认为是高风险

  • 人担心他们的混合类注解(元信息)是错误的。

任何其他可能的解释?

推荐答案

域名层和持久层被一些人认为是独立的担忧。使用纯XML方法可以使松散耦合尽可能两层;使用注释夫妇两层越紧,你必须嵌入域code持久性相关的code。

The domain layer and the persistence layer are considered by some to be separate concerns. Using the pure XML approach keeps the two layers as loosely coupled as possible; using annotations couples the two layers more tightly as you have persistence-related code embedded in the domain code.

这篇关于为什么人们继续使用XML映射文件,而不是注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:14