Hibernate 6 mapping without annotations

1.5k Views Asked by At

Up to Hibernate 5 the class mapping can be defined either by using JPA annotations or with an XML file. The XML file is convenient because it isn't tied to the class, which means it's possible to:

  1. map a class even if you don't have the source code
  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)

Hibernate 6 removed the XML mapping. Is there an alternative method to define a mapping without adding annotations to the persisted classes?

2

There are 2 best solutions below

0
Gavin King On BEST ANSWER

We now recommend the use of the standard JPA ORM mapping format, which is orm.xml.

For Hibernate-specific extensions to the orm.xml format you can find mapping-3.1.0.xsd here:

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

I guess this is what you're looking for.

2
Guillaume On

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