简体   繁体   English

Hibernate 6 映射无注释

[英]Hibernate 6 mapping without annotations

Up to Hibernate 5 the class mapping can be defined either by using JPA annotations or with an XML file.最多 Hibernate 5 可以使用 JPA 注释或 XML 文件定义 class 映射。 The XML file is convenient because it isn't tied to the class, which means it's possible to: XML 文件很方便,因为它没有绑定到 class,这意味着可以:

  1. map a class even if you don't have the source code map 一个 class 即使你没有源代码
  2. map a class differently depending on the context (a class may be mapped one way on the server, and another way on the client) map class 根据上下文不同(class 可能在服务器上以一种方式映射,在客户端上以另一种方式映射)

Hibernate 6 removed the XML mapping. Hibernate 6 删除了 XML 映射。 Is there an alternative method to define a mapping without adding annotations to the persisted classes?是否有另一种方法可以在不向持久类添加注释的情况下定义映射?

Unless I missed something hbm XML mappings are still in Hibernate 6 but now they are officially deprecated: https://docs.jboss.org/hibernate/orm/6.0/migration-guide/migration-guide.html#_deprecation_of_hbm_xml_mappings除非我错过了什么 hbm XML 映射仍在 Hibernate 6 但现在它们已被正式弃用: https://docs.jboss.org/hibernate/orm/6.0/migration-guide/migration-guide.html#_deprecation_xml_of_maphb

We now recommend the use of the standard JPA ORM mapping format, which is orm.xml .我们现在推荐使用标准的 JPA ORM 映射格式,即orm.xml

For Hibernate-specific extensions to the orm.xml format you can find mapping-3.1.0.xsd here:对于orm.xml格式的特定于 Hibernate 的扩展,您可以在此处找到mapping-3.1.0.xsd

https://hibernate.org/xsd/orm/mapping/mapping-3.1.0.xsd https://hibernate.org/xsd/orm/mapping/mapping-3.1.0.xsd

I guess this is what you're looking for.我想这就是你要找的。

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

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