简体   繁体   English

Hibernate 5是否支持基于XML的实体映射?

[英]Does Hibernate 5 support XML based entity mappings?

Hi my question is not technical. 嗨,我的问题不是技术问题。 I want to know if hibernate 5 supports XML based entity mapping or not. 我想知道hibernate 5是否支持基于XML的实体映射。

My requirement is like below : 我的要求如下:

I want a backend on Jersey-Hibernate. 我想要Jersey-Hibernate的后端。 My front end is Android application. 我的前端是Android应用程序。 I want to keep my Entity POJOs in a common project such that they will be shared by both app and server. 我希望将我的实体POJO保存在一个通用项目中,以便它们将由应用和服务器共享。 Gson will serialize/deserialize both side. Gson将对两方进行序列化/反序列化。 But because android application doesn't support all java library in compilation, I don't want my common(POJO) depending on some library; 但是因为android应用程序不支持编译中的所有java库,所以我不希望我的常用(POJO)依赖于某些库; In this case hibernate annotations. 在这种情况下,hibernate注释。 So I am planning to use XML based configuration. 所以我打算使用基于XML的配置。

Hibernate 5 supports both the legacy HBM mappings as well as the JPA XML mappings too. Hibernate 5既支持传统的HBM映射,也支持JPA XML映射。 However, HBM mappings are no longer the recommended approach to map entities. 但是, HBM映射不再是映射实体的推荐方法。 As illustrated in the new User Guide , all examples make use of annotations. 新用户指南中所示 ,所有示例都使用注释。

There are more features provided by Hibernate-specific annotations than it is the case with HBM mappings. HBM映射的情况相比,特定于Hibernate的注释提供了更多功能。 In Hibernate 6, it is planned to add an extension mechanism to the JPA XML mappings, therefore HBM mappings are deprecated. 在Hibernate 6中,计划为JPA XML映射添加扩展机制,因此不推荐使用HBM映射。

Since you are migrating to Hibernate 5, it's a good idea to migrate from HBM to annotations too. 由于您要迁移到Hibernate 5,因此从HBM迁移到注释也是一个好主意。

Yes, according to documentation (where authors recommended using annotations for mapping) is said that xml mapping is still possible: docs 是的,根据文档(作者建议使用注释进行映射),可以说xml映射仍然可行: docs

So on - you can still us *.hbm.xml for entity mapping. 所以 - 您仍然可以使用*.hbm.xml进行实体映射。

EDIT: ofc I mean *.hbm.xml 编辑:ofc我的意思是* .hbm.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM