I'm just wondering why the combination of Spring and Hibernate is so popular, when it would be possible to leave Hibernate out and use just Spring ORM?
Spring is popular because it takes care of the 'boilerplate' cut and paste code you have with any ORM framework. Think try ... finally
blocks, dealing with the session object (Hibernate or otherwise) and commit / rollback
(transactions).
Transaction management is also Spring's strength. You can define transactions using annotations or in the Spring xml config file. In the config file, the benefit is that you can use wildcards to specify that, for example, all find methods in some set of packages should support transactions (PROPAGATION_SUPPORTS) but all insert, update, delete methods should require transactions (PROPAGATION_REQUIRED).
So, I would always use Spring, regardless of the ORM framework. If you have simple requirements or not that much JDBC code, Spring's JDBC templates may be enough for you. And, Spring makes it easy to upgrade to Hibernate when needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With