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
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.
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.
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.
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.
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.
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:
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.
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