Hibernate映射文件和注释的区别 [英] Difference between Hibernate mapping file and annotation
本文介绍了Hibernate映射文件和注释的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天我试图用Hibernate创建一个应用程序作为ORM。所以在创建时我有一个疑问。什么是最佳实践,Hibernate映射文件(.hbm文件)或注释?它有什么优点和缺点?请帮助我理解。
Today I was trying to create a application using Hibernate as ORM. So while creating I had a doubt. What is the best practice to use, Hibernate mapping file (.hbm file) or annotations ? What are the pros and cons of it ? Please help me in understanding.
推荐答案
- 没有功能差异。您可以使用这两种方法执行(几乎)相同的操作 在Java有注释之前使用了
- xml文件(在1.5中添加),因此它们可以被认为是过时的映射方式 >
- 通常最好使用JPA注释而不是特定于hibernate的注释;如果使用xml - 有一个JPA xml格式,它应该优先于休眠本地文件。
- there is no functional difference. You can do (almost) the same things with both approaches
- xml files were used before Java had annotations (added in 1.5), so they can be considered an outdated way of mapping
- it is generally preferred to use JPA annotations rather than hibernate-specific ones; if using xml - there is a JPA xml format, which should be preferred to hibernate native one
这篇关于Hibernate映射文件和注释的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文