Guidance Needed: Migration Strategy from hbm.xml to orm.xml for Hibernate 7.x Upgrade

Hi @beikov,

Need your suggestions regarding our project upgrade path:

  1. We successfully upgraded from 5.x to 6.6.x, but with 7.x release, 6.x is now in limited support
  2. We haven’t converted our mapping files (800+ hbm.xml files) which we use with hibernate tools to generate entity classes
  3. Questions:
  • Has hbm.xml support been removed in 7.x?
  • If yes, could you suggest how to migrate to orm.xml?
  • Are there any tools available to generate entity classes from orm.xml?
  • Manual creation of entity classes would be challenging given the volume

Your guidance on how to proceed would be greatly appreciated.

No, what made you think that? :thinking:

That’s planned (tentatively?) for 8.0.

Not that I know.

The idea of an automated tool to convert hbm.xml to orm.xml was mentioned at some point. I think @sebersole started implementing it, but I’m not sure what the current status is (couldn’t find it mentioned in the 7.0 migration guide).

Last time, Christian said this Slight correction, ORM 7.0 might actually remove hbm.xml support already: HHH-19324 - Switch tests using hbm.xml to use mapping.xml by sebersole · Pull Request #9956 · hibernate/hibernate-orm · GitHub

I am having one more question actually, if we are having entity classes with JPA annotations do we still require a mapping file like (orm.xml)?

Okay, well that was wrong. As mentioned in the PR:

Once all tests have been converted and gaps addressed (which just might mean Jira created for thre moment), we can start actually removing the code for applying hbm.xml - though that will be 8.x specific

No, orm.xml is entirely optional.

As far as I know it’s mostly useful if you cannot use annotations (entity classes coming from a separate JAR) or to pick a different mapping on startup (switching from one orm.xml to another). There might be other use cases.

orm.xml can also be mixed with annotations, and there the orm.xml mapping will be “laid over” annotations. Though I’m not sure of precedence.

Does there come a new version of Hibernate Tools with the release of Hibernate 7.x? What is this new mapping.xml is this same as orm.xml? - just the name got changed?

It’s just the name of Hibernate ORM’s “extended” orm.xml, as far as I can see. orm.xml still works.

Oh, I just found that: hibernate.transform_hbm_xml.enabled. Can’t find it in the reference documentation though, it must be experimental.

If I use this settings, it will convert the hbm.xml to mapping.xml? at runtime?
Our hbm.xml files are very older one, when I use the setting you mentioned, I got this exception

Caused by: java.lang.UnsupportedOperationException: Transformation of <meta/> (tooling hint) is not supported - `Origin(name=chs/pof/Sharedconductorcustomattributes.hbm.xml,type=RESOURCE)`
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.handleUnsupported(HbmXmlTransformer.java:254)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.transferToolingHints(HbmXmlTransformer.java:1028)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.transferBaseEntityInformation(HbmXmlTransformer.java:1014)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.transferRootEntity(HbmXmlTransformer.java:812)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.transferEntities(HbmXmlTransformer.java:775)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.doTransform(HbmXmlTransformer.java:226)
	at org.hibernate.boot.jaxb.hbm.transform.HbmXmlTransformer.transform(HbmXmlTransformer.java:181)
	at org.hibernate.boot.jaxb.internal.MappingBinder.doBind(MappingBinder.java:220)
	at org.hibernate.boot.jaxb.internal.AbstractBinder.doBind(AbstractBinder.java:96)
	at org.hibernate.boot.jaxb.internal.AbstractBinder.bind(AbstractBinder.java:51)
	at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:43)
	... 9 more

I forgot to mention that we use this tag to import our own annotations, with these annotations only we manager our CRUD operations. I can see that this tag is not supported while conversion.

As I said, it’s experimental.
And indeed I don’t think all features of hbm.xml can/will be supported. There’s another property for ignoring unsupported features if that’s fine by you – otherwise I’d recommend moving away from the more obscure features if you can.