Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring vs Hibernate

Just trying to get my head round Spring and figuring out how I wire up an Oracle connection in xml config file, and now find out I need yet another framework! - Hibernate, this is soooo frustrating as it feels like I'm getting deeper and deeper into more and more frameworks without actually getting what I need done!

I looked at Hibernate and it seems to do similar things to Spring, bearing in mind I just want to do some SQL inserts in Oracle.

I am reluctant and do not have time to learn 2 frameworks - could I get away with just adopting Hibernate for the simple things I need to do?

like image 246
Vidar Avatar asked Feb 09 '09 20:02

Vidar


People also ask

Which is better Hibernate or Spring?

Hibernate is for ORM ( object relational mapping ) that is, make your objects persistent to a RDBMS. Spring goes further. It may be used also as a AOP, Dependency Injector, a Web Application and ORM among other things. So if you only need ORM, just use Hibernate.

Is Spring and Hibernate same?

Hibernate provides Object-Relational Persistence and Query service for applications. Spring has a number of modules such as Spring core, Spring MVC, Spring Security, Spring JDBC & more. Hibernate is an ORM and does not have modules like Spring.

What is the difference between Spring data and Hibernate?

Hibernate is a JPA implementation, while Spring Data JPA is a JPA data access abstraction. Spring Data JPA cannot work without a JPA provider. Spring Data offers a solution to the DDD Repository pattern or the legacy GenericDao custom implementations.

How is Hibernate different from Spring boot?

The difference between Spring and Hibernate is that spring is a complete and a modular framework for developing Enterprise Applications in Java while Hibernate is an Object Relational Mapping framework specialized in data persisting and retrieving from a database. Hibernate is integrated into to Spring framework.


3 Answers

...could I get away with just adopting Hibernate for the simple things I need to do?

Yes

Hibernate is for ORM ( object relational mapping ) that is, make your objects persistent to a RDBMS.

Spring goes further. It may be used also as a AOP, Dependency Injector, a Web Application and ORM among other things.

So if you only need ORM, just use Hibernate. Time will come when you need Spring, and you will learn it then.

Here's an architectural view of Spring:

spring

And this is Hibernate:

hibernate

like image 167
OscarRyz Avatar answered Oct 04 '22 12:10

OscarRyz


Spring and Hibernate are totally different frameworks for different problems. Spring is a huge framework with many many features, Hibernate is an O/R bridge.

I would recommend using plain old JDBC in your case ('just some SQL inserts in Oracle').

like image 40
André Boonzaaijer Avatar answered Oct 04 '22 13:10

André Boonzaaijer


You could get away with using just spring and spring-JDBC integration. Depending on the complexity of your data-access needs it may be more than enough. The spring Object-relation mapping is also worth looking into if you're going to do a lot of data-access.

The nice thing about spring is that it's a very loosely coupled framework. So you can read up on the bits you use, and forget the rest - even in the runtime.

like image 34
krosenvold Avatar answered Oct 04 '22 13:10

krosenvold