是否有充分的理由使用 XML 而不是通过注释配置休眠? [英] Is there a good reason to configure hibernate with XML rather than via annotations?

查看:23
本文介绍了是否有充分的理由使用 XML 而不是通过注释配置休眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Hibernate 几年了,但只将它与注释一起使用,并通过在我的代码中设置连接参数.

I've been using Hibernate for a few years but have only used it with annotations, and by setting the connection parameters in my code.

我是否因为不使用 XML 文件而遗漏了什么"?是否有仅在 XML 中可用的重要功能?是否存在使用 XML 有意义的情况或模式?

Am I "missing something" by not using the XML files? Are there important capabilities available only in XML? Are there situations or patterns where it makes sense to use the XML?

推荐答案

我认为可以肯定地说,您没有错过任何事情.

I think it's pretty safe to say that you're not missing out on anything.

如果 XML 中有任何不能用属性表示的功能(我相信有一些罕见的情况),那么您仍然可以选择使用 [RawXml] 并在属性中编写 XML.因此,您不会错过任何功能.

If there are any capabilities in XML that can't be represented in attributes (and I believe there are some rare cases) then you still have the option to use [RawXml] and write the XML in the attribute. So you can't possibly miss out on any functionality.

如果您的团队中有足够多的程序员只是喜欢管理单独的文件,或者如果确实需要即时编辑 xml 映射,那么使用 XML 可能是有意义的.对于非常复杂的映射,XML 映射文件可能更容易操作,并且它们可以包含有用的信息(对获取策略的评论等).

It might make sense to use XML if you have enough programmers in your team who simply prefer to manage separate files or if there is a genuine need to edit xml mappings on the fly. Xml mapping files are probably easier to manipulate for very complex mapping and they can contain useful information (comments on fetching strategies etc).

还有架构问题,有些人认为将映射分离到 XML 文件中可以更好地分离业务相关代码和关于如何持久化的指令.

There is also the issue of architecture, where some people argue that separating the mapping into XML files provides a better separation between business-related code and instructions on how it is persisted.

这篇关于是否有充分的理由使用 XML 而不是通过注释配置休眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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