Hbmxml files vs annotated class files

We are currently trying to migrate from Hibernate 5.6 to Hibernate 6.5 and currently our entire approach has been to use the hibernate configuration files (hbmxml) for our entity classes. But we have seen that the Annotation approach seems to be more modern way of doing things.

Firstly, we wanted to know the significant advantages of Annotated class files.
Secondly, we wanted to know if there are any hibernate tools which we can use to convert the xml files to annotated class files.

Hibernate’s custom hbm.xml format is considered deprecated and will eventually be dropped in favor of the new standard orm.xml. There are tools, like the hbm.xml transformer available also in the Gradle - Plugin: org.hibernate.orm, which allows you to automatically migrate most of your mappings from one format to the other but will require manual intervention to fill in the gaps.

In Hibernate 7, we will be improving the transformer to be able to handle most if not all legacy mappings. I strongly suggest migrating to either annotations or the newer orm.xml format as probably in a future version hbm.xml will no longer work.

Thank you for the quick response @mbladel
Will try out your suggestions and let you know how it goes.

Hi @mbladel
To give you a sense of context, our product is like a framework in which hibernate is also a part and we have a lot of legacy users who have been with us since a lot of years. These users have been used to using the hbm.xml files and for them to be moving to annotated class files would be a major change. The orm.xml would be ideal for us to migrate to as it won’t be changing the use case for the customers to a large extent. Hence we want to know the following information about the orm.xml

If we do migrate to the orm.xml file format instead of the annotated class files, are we missing out on the new features which are being released in the hibernate versions? Because I see that a lot of the new features are mostly annotation based so I wanted to know if there are xml equivalents for all of them?

We also wanted to know about the performance of orm.xml file and how it compares to the annotated class files. Is either of them significantly better than the other in any regard? If so, can you shed some light on that?

Do you have a transformer tool which is maven based? Since our entire project is maven based itself, it would be of great help if that is available.
Pardon me if I am may be reiterating the same thing here but I wanted to know if you provide any transformer tool which converts the hbm.xml files to annotated class files?

Lastly, Based on your experience which approach do you see is more widely adopted and would be the recommended way going forward?

New features are progressively added for each minor version. During the development of Hibernate 6.x, the orm.xml definition did not receive “feature-parity” of all the things that were added. We’re planning to reset this in version 7.0, though, by aligning the available features as much as possible. I cannot assure you that in the future the XML format will be always in line with annotations, but we hope to be able to keep it up to speed.

We also wanted to know about the performance of orm.xml file and how it compares to the annotated class files

Performance is relative, in one case we’re relying on reflection scanning the annotated class path, in the other we’re parsing XML files. For huge mappings (i.e. > 1000 entity types), I can see this making a difference, but for most normal applications it shouldn’t matter. Note that mappings are processed only once, at the boot time of your application, so the runtime performance won’t be affected at all.

Do you have a transformer tool which is maven based?

Not for now, we’re evaluating a possible maven plugin for the transformer in version 7.0 but there’s not definitive plan yet.

I wanted to know if you provide any transformer tool which converts the hbm.xml files to annotated class files?

Yes, the HbmXmlTransformer I already mentioned in my previous comment, you can enable it through this configuration property. Once again, it’s not perfect and it’s going to need manual corrections, but it should give you a starting point. In 7.0 we’re working a lot to make it more reliable, so you might want to wait for that.

which approach do you see is more widely adopted and would be the recommended way going forward

For modern applications, annotations are the way to go. But I understand that migrating a legacy code base which might involve different people is very hard, if not impossible at times, that’s why we’re trying to make the transformer as good as possible to ease the migration into 7.0.