Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring ORM or Hibernate

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?

like image 373
John Manak Avatar asked Sep 29 '10 14:09

John Manak


1 Answers

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.

like image 180
AngerClown Avatar answered Nov 15 '22 21:11

AngerClown