aspose file tools*
The moose likes Spring and the fly likes Choosing between Spring JDBC Template or Spring JPA or Hibrenate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Choosing between Spring JDBC Template or Spring JPA or Hibrenate" Watch "Choosing between Spring JDBC Template or Spring JPA or Hibrenate" New topic
Author

Choosing between Spring JDBC Template or Spring JPA or Hibrenate

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 541
In any application how to decide whether we should go for Spring JDBC Template or Spring JPA or Hibrenate.
thanks.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Well your first question is really should I use straight JDBC or should I use an ORM?

ORM's offer a lot of benefits but there is also pitfalls for the inexperienced. If your talking about a production application I think it comes down to what your teams abilities are and if they have the comfort level and experience to support and write proper code using an ORM. If they are I would go with the ORM otherwise probably JDBC.

If you are talking about a personal project with the goal of learning, I would start with Spring JDBC (JDBC Template) if you are not very familiar with it yet. If you are comfortable with straight JDBC then I would go ahead and start delving into the world of ORM and learn that next, but definitely in that order.

Hibernate is just one persistence provider which is a fine choice. On top of that there is JPA which is a specification. I would choose this over hibernate specific code. Spring data is another project which abstracts things even more and is definitely worthwhile if you choose the ORM route.


[How To Ask Questions][Read before you PM me]
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 541

Thank You. I understood the advantage of ORMs to normal JDBC and have already used JDBC template and hibrenate in appications.However my doubt is that for an application

when to go for Hibernate over JPA,Sping JDBC template ?
when to go for Sping JDBC template over JPA,Hibernate?
when to go for JPA over JPA,Sping JDBC template?

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

I would always choose JPA over vanilla hibernate. The only time I wouldn't is if it is a pre-existing application where it would be major rework to make it JPA. If there is a specification best to try to use it, that way if you want to switch out persistence providers later it is an easy task.

I would always choose JPA over JDBC
1.If I have a team that has a good grasp of JPA or I am the only developer.
2. The data model easily supports it (There have been a couple times where the data model on some legacy DB is such a mess that I have chosen JDBC not because it could not be done with JPA, but it would have been a bigger headache then it is worth.)
3. The environment has enough resources to support the ORM (a few projects I have been on required a really lean dependency tree)


If you are using JDBC and Spring I would always use JDBC Template.
If you are using JPA and Spring I would always use Spring-data JPA.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Just to concur. Bill's last post is exactly what my recommendations would be.

Personally I would always use Spring Data JPA for relational databases, because I am an expert and know how to write it such that the data access is faster than straight JDBC. But you have to have an expert on your team. If not, you will cripple your application by doing things wrong.

I also use NoSQL, so I use Spring Data modules for the NoSQL databases that I also use.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Choosing between Spring JDBC Template or Spring JPA or Hibrenate
 
Similar Threads
Help needed in Spring's JDBC Template !!!
Tomcat Startup Error
How to handle stored procedures
which technology
Connecting to Database using JDBC template (Spring)