Transaction management alternatives?

Hi

I am working on migrating some pretty old hibernate code to something that could run on Spring Boot. Usually an infrastructure team has handled all the lowlevel Hibernate stuff, but now I am on my own, and pretty confused.

My first attempt is basically a variation on the Caveat Emptor example, i.e. manual transaction management in each DAO type method. It works, but is quite tedious and cumbersome.

Moving forward from that, I have a couple of questions:

  • Does Hibernate have native declarative transactions or anything similar to what Spring offers?
  • If not, what are the options for designing transaction management in a simpler and not as intrusive way? I am interested in design suggestions, in this respect.

Thanks, Tom

If you’re not sold on Spring yet, I would suggest you to use Quarkus instead, since that has a way better integration with Hibernate ORM. The Hibernate Team also works on Quarkus, whereas Spring “just” integrates Hibernate ORM without anyone of the Hibernate Team knowing or working with Spring technology very well. The Spring team also doesn’t really contribute to Hibernate ORM, so if you have questions or issues, you might end up getting sent back and forth between forums. Using Quarkus would provide you way better experience, since the Hibernate team also answers questions in the Quarkus forums.

Having said that, the defacto standard is to use the jakarta.transaction.Transactional annotation on your bean class or method. Spring also has its own annotation, but supports the Jakarta one as well.

Hi beikov.

Being sent back and forth between here and the spring stackoverflow forum sounds familiar. I’ve recently been thinking about Quarkus as an actual alternative, but I have no experience with it, only Spring and Spring Boot. (I am a single developer and its a critical system :unamused_face: , so not sure about the risk just yet).

In any case… What you are saying is that Hibernate has no implementation for @Transactional?

Thanks, Tom

It’s actually not that hard to switch to Quarkus. Also see Quarkus for Spring Developers - Quarkus which points to a free E-book that you can use as resource along with the getting started guides that are linked.

Hibernate ORM as of version 7.0 has a inTransaction() method that accepts a lambda which simplifies manual transaction handling by a lot, but that’s all Hibernate ORM can offer.
Declarative transactions require integration with the bean/component system of a runtime, as well as potential integration with other transactional systems that are not JDBC, so this is left to runtimes like Quarkus and Spring.