Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Hibernate Vs jdbc template vs spring orm [closed]

We have a project with MySQL database and Spring as the framework. I am very new to Spring and looking to implement the database access layer and found that there are several options available, like

  • Using Spring + Hibernate
  • Using Spring JDBC Template
  • Using Spring ORM Module

I have gone through the various posts in stackoverflow and did a bit of research on the web, but every question had different answers supporting different options. Also, I did see a mention about Spring JDBC template not being recommended now.

The application might have approximately 1000 transactions per hour and have 60% reads and 40% writes, approximately.

Can anyone help me in finding an answer as to which of the 3 options is suitable and why ? Or, if you can point me to some resources, that would be highly appreciated as well.

like image 746
Sunil Avatar asked Aug 07 '12 16:08

Sunil


People also ask

What is the difference between Spring JDBC template and hibernate?

JDBC enables developers to create queries and update data to a relational database using the Structured Query Language (SQL). Hibernate uses HQL (Hibernate Query Language) which is similar to SQL but understands object-oriented concepts like inheritance, association etc.

Is spring a JDBC ORM?

Spring Data JDBC aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of JPA. This makes Spring Data JDBC a simple, limited, opinionated ORM.

Which is better JDBC template or JPA?

Also, JPA is thought to be better suited for more sophisticated applications by many developers. But, JDBC is considered the preferable alternative if an application will use a simple database and we don't plan to migrate it to a different database vendor.

Is JDBC template faster than JPA?

At work we use Hibernate JDBCTemplate because it has more flexibility. It also has better performance than JPA because you are not "loading" a lot of unnecessary data into your app. In the JDBCTemplate case, your SQL skills go a long way in giving you exactly what you need at the right speed.


1 Answers

Hibernate is just one of the many ORM solutions that Spring supports; others are listed here.

You might choose ORM if all of the following were true:

  1. You had a solid object model to map relational data to.
  2. You liked the SQL generated for you by the ORM layer.
  3. Your schema conformed nicely to the requirements of the ORM solution.
  4. You weren't using a lot of stored procedures.
  5. You didn't think you could optimize SQL better than the ORM could.

If any of those aren't true, maybe an ORM isn't for you.

Spring JDBC template is light and simple. I would bet that it could accomodate your stated requirements. I'd recommend going with that until you found out that your requirements drove you to ORM. If you follow the typical Spring idiom and create an interface-based persistence layer, this will mean injecting one implementation instead of another.

like image 110
duffymo Avatar answered Sep 24 '22 23:09

duffymo