JDBC vs JPA: Pros and Cons

  Рет қаралды 25,856

Pro Coder

Pro Coder

Жыл бұрын

JdbcTemplate. Spring Data JPA. Spring Data JDBC.
Which one do I pick? What are the tradeoffs? Do I have to go all the way with my choice?
If these questions plague you when working on persisting data in your Spring Boot application, then this video is for you!
====
Don't forget to pre-order your copy of Learning Spring Boot 3.0 3rd Edition today at springbootlearning.com/book!
====
ALSO SEE: 👀
✅ What are DTOs? • DTOs in Web Developmen...
✅ What is JDBC? • Why does this matter f...
✅ What is JPA? • WHY should I use JPA?
RESOURCES: 👇
- Order your copy of Learning Spring Boot 3.0 3rd Edition today at springbootlearning.com/book!
- Spring Boot: Up & Running (Mark Heckler): trnq.st/wv3z
- Spring in Action (Craig Walls): trnq.st/0sbr
- Bootiful Podcast: trnq.st/zfqi
- Java Pub House: trnq.st/okx8
- Spring Boot Learning Podcast: springbootlearning.com/podcast
- Dan Vega's KZfaq channel: / @danvega
- Spring team's official channel: / @springsourcedev
- This channel's github repositories: trnq.st/sfd5
GET MORE: 🎉
- Get a FREE tech ebook at springbootlearning.com/join
- Follow me on Twitter: / springbootlearn
GRAB A MUG FOR YOUR COFFEE ☕ (and a t-shirt): store.springbootlearning.com/
Click "subscribe" under the video (and hit that bell icon) to get notified when new videos come out.
STUFF I LIKE TO USE: 😍
- Studio gear: springbootlearning.com/kit
- Laptop stand: springbootlearning.com/twelve...
- Motorized standing desk: springbootlearning.com/desk
- Music: springbootlearning.com/epidem...
- Recut (pre-editing): springbootlearning.com/recut
- Thumbnail Testing: springbootlearning.com/thumbn...
- Best place to run Spring Boot apps: tanzu.vmware.com/
DISCLOSURE: All opinions stated here are mine and do not necessarily reflect those of the Spring team nor of my employer. Any usage of "Spring", "Spring Boot", "Spring Framework", "VMware", "Pivotal", or anything else is completely unaffiliated with its owners. From time to time, I may post affiliate links for products I enjoy using. They don't cost you anything extra, and I may get a small commission.
#springbootlearning
© 2022 Greg L. Turnquist, All Rights Reserved

Пікірлер: 21
@jaysizmir9432
@jaysizmir9432 Жыл бұрын
Love the way you explain things, thank you !
@adamohm
@adamohm 5 ай бұрын
Very informative video, it helped me a lot. Good job and thank you!
@maxfreund4803
@maxfreund4803 14 күн бұрын
Love your explanations, man :)
@adrianbornea
@adrianbornea Жыл бұрын
Good explanation. Subscribed 👍🏻
@ProCoderIO
@ProCoderIO Жыл бұрын
Thanks!
@balajir6670
@balajir6670 Жыл бұрын
Very good explanation, thank you
@ProCoderIO
@ProCoderIO Жыл бұрын
What else needs to covered?
@dowoyele
@dowoyele Жыл бұрын
Great video. Thank you. But should I learn JDBC or JPA. I feel like since JPA is more often used than JDBC, I should concentrate on JDBC. Please what do you think?
@ProCoderIO
@ProCoderIO Жыл бұрын
I’d start with Spring Data JPA. Get your feet wet with JPA. It’s a very commonly used library. No harm learning. But it can also let you learn the shortcomings of JPA and what in turn; what Spring Data JDBC has to offer.
@danielbristol6794
@danielbristol6794 Жыл бұрын
In terms of performance like querying millions of records from database, which is faster?spring data jpa or jdbc?
@ProCoderIO
@ProCoderIO Жыл бұрын
JPA is a bit tricky in these scenarios. JPA is simply a higher level query language translated into SQL by the JPA provider, so in the end, it becomes JDBC. The simplest queries would be probably be identical. Ensuring you have the right indexes and are running stats on the database are important. But when it comes time to "tune" your query based upon DBA feedback, it may be trickier to tune JPQL (or not). Again, depends on the scenario. This level of separation between written and actual query is what I feel made people VERY interested in Spring Data JDBC, and willing to trade in some of the JPA's feature set to get a little more control over the SQL.
@andrascsovari8607
@andrascsovari8607 Жыл бұрын
Great video, thanks for it also these lights make me feel uncomfortable, natural would work better for me
@danhoward7697
@danhoward7697 Жыл бұрын
Persism is a often better option than those. Check it out.
@ProCoderIO
@ProCoderIO Жыл бұрын
Took a peek. Interesting approach. Unfortunately it only has one committer and no changes for 8 months. As for “better than those”, Persism uses JDBC under the hood. Just check out github.com/sproket/Persism/blob/persism2/src/net/sf/persism/ConnectionType.java. Also, if I may add, kind of strange to bake in all your supported platforms instead of making it open ended.
@panchal6360
@panchal6360 Жыл бұрын
Hey thanks for the explanation. Now i don't have to watch 3 different videos.
@ProCoderIO
@ProCoderIO Жыл бұрын
Awesome! Is there something else you've been eager to see that would be handy as a video?
@panchal6360
@panchal6360 Жыл бұрын
Hmm, maybe some information about feignclients would be great. Btw thanks.
@timw594
@timw594 11 ай бұрын
I think this is a great video, but there are some old myths talked about here that frankly remain myths and many just wrong. #1. Companies are 4 to 5x more likely to change the programmatic front-end UI and app stack then they are the actual backend RDBMS. #2. far more rare is to decide to change the RDBMS alone.... almost 95% of the time when they are changing the RDBMS they are also changing the entire tech stack (aka company acquistion, merger etc...) #3. There is more standard cross functionality in the main RDBMS platforms than any front-end UI app stack created to date. If you look at PL/SQL and SQL across the big vendors DB2, Oracle , MySQL, SQL Server vs Postgres. The truth is about 95% of what you need and use most frequently is about 95% the same across all of the vendors. There use to be allot more differences in the 90's and early 2000's but the good thing about RDBMS and the SQL ansi standard is that almost all of these vendors end up landing in the same area when it comes to standards and evolved in the same ways. #4. Trying to pretend like any of these stacks are going to keep you out of the late night calls on "Forgot to close a cursor"... or a transaction log filled up... or someone did a cartesian product is 100% untrue when on any project of complexity. This is why you either make sure someone on your team has expertise in backend app development or in many situations a DBA can pull double duty to keep this from happening. Matter of fact having good backend knowledge on the team to start with will keep you out of ALL of these problems and make the stack much much simpler. #5. SQL and PL/SQL are INCREDIBLY easy and they haven't changed much in 30+ years... and they handle things more efficiently inside the RDBMS than any outside language can. And on almost every project and simple and complex CRUD operations can be centrally controlled in one location for tuning, adding additional outside of core app functionality etc. #6. Many times these days a business database will have more than one interface and centrally locating/abstracting CRUD operations in the database centrally control the logic/behavior and eliminate multiple front-end access points from having variation in they way they say... Create a new customer... create a new contract etc...
@ProCoderIO
@ProCoderIO 11 ай бұрын
Glad you liked the video. And you have some very valid points (thanks for writing them in such detail). I'll try to respond to each one below: #1 - Agreed. Changing the backend is VERY rare. #2 - Agreed. I was trying to speak to the point where you get sold this bill of goods about "JPA protects you from the underlying DB." Companies don't REALLY change that much. But developers seem prone to lap this one up, as if writing JPA is somehow "easier" than writing for the platform that you're on. #3 - This is indeed true. Most of the "core" SQL stuff we use today works pretty well on all of them. It's just little stuff like "string concatenation" I've stumbled across is NOT portable. Also, some of the newer features like JSON operators tends to be platform-specific and NOT found across all the platforms. And yes, the era I wrote gobs of SQL was early 2000s, so when I'd spend weeks working on Oracle and then attempt to fashion a query for some business analyst in MS Access, I'd get burned on little stuff. #4 - I got called in plenty of times for the database being maxed out. Sometimes during the day. But often it would happen at night. Once, I was called in 3x on the same night, albeit not for being out of cursors. But the "forgot to close your cursors" thing was real for not just me but others on our team. And it would hit us again. Probably because we would implement three queries at once and "forget" to properly close all three. Murphy's Law?? Anyway, one would be the breaking point. We'd fix it. And it would take 6-12 weeks for the NEXT one to reach some breaking point. Rinse/repeat. This was a mixture of good ole J2EE back in the day for one app, and a non-Java app for another, we'd see the problem on both. Tools like Spring's JdbcTemplate, were it adopted, would eliminate a whole class of errors from ever happening. Pretty good bargain in my book. #5 - Yes, stored procedures and views and other things that move stuff INSIDE the DB typically are more performance. But you tend to migrate toward a different development style. We frankly would have required more time contribution from our DBA team to do that. And we had a limited budget. App developers writing SQL queries in their applications was an agreeable approach compared to stuffing everything into stored procedures and then tapping the DBA team when the stored procedure had to be patched/updated. At that point, you aren't really DOING data persistence in your application. You're just invoking remote APIs through the database driver. And this can be done with either JPA or JDBC. The differences between the two kind of dwindle in that context. As for how "easy" that approach is well...I watched someone that was supposedly better at SQL/PLSQL than me build a query by joining multiple views together to get the results he needed. Guy didn't realize he was joining the same table 20 times, thus causing the query to take 20 minutes to run. When he rolled off the contract and I picked up his app, it took me three weeks to grok it and then rewrite it. Query went sub-second and the department using it gave me a cute certificate award. Not everyone comprehends relational databases. Part of my point of this video is that developers, for years, were pitched that JPA/Hibernate makes it where you don't HAVE to understand the database. And that is simply wrong. #6 - That is a VERY valid point. If the database is simply the raw data and each app is gluing it together differently, you run the risk of not upholding the contract. We had the fortune of having one person from the DBA team assigned to the developers team so that we could ensure that ALL of us were doing the "same thing" with regarding to the data. The fact that we couldn't practically adopt stored procedures nor were we all even using the same technology (Java vs. Non-Java apps) meant we REALLY had to ensure our queries & views were properly aligned. And this guy helped us do just that. I'm hoping to not purport myths but instead address some of the assumptions people make with what JPA is and what JDBC is. And that by digging a little deeper, and understanding a little more, people can better use both of these technologies to achieve their solutions. Thanks for stopping by. Hope you'll tune in for more of my videos!
@timw594
@timw594 11 ай бұрын
@@ProCoderIO very good stuff here seriously. Thanks for the detailed response. Im a full stack developer but a deep data engineer and architect w heavy RDBMS background... I guess I personally at these persistence layers at being allot more complex vs leveraging the RDBMS directly. As to where others might feel it's easier the other way.
HOW to be a REMOTE Engineer
23:07
Pro Coder
Рет қаралды 769
Андрей Беляев - JPA-паззлеры (+Hibernate и Spring)
1:04:57
JPoint, Joker и JUG ru
Рет қаралды 20 М.
Сын Расстроился Из-за Новой Стрижки Папы 😂
00:21
Глеб Рандалайнен
Рет қаралды 6 МЛН
How to open a can? 🤪 lifehack
00:25
Mr.Clabik - Friends
Рет қаралды 11 МЛН
What is Jakarta EE?
8:41
Pro Coder
Рет қаралды 10 М.
WHY should I use JPA?
10:29
Pro Coder
Рет қаралды 2,8 М.
Что такое JDBC? Что такое ORM, Hibernate & JPA?
12:59
Sergey Nemchinskiy
Рет қаралды 71 М.
Spring Data JPA from 0-100 in 60 minutes
1:02:31
VMware Tanzu
Рет қаралды 80 М.
JPA And Hibernate Tutorial For Beginners with Spring Boot and Spring Data JPA
57:15
in28minutes - Get Cloud Certified
Рет қаралды 216 М.
Java Database Connectivity | JDBC
20:34
Telusko
Рет қаралды 177 М.
Самый маленький игровой ПК
0:46
ITMania - Сборка ПК
Рет қаралды 624 М.
Samsung or iPhone
0:19
rishton_vines😇
Рет қаралды 2,1 МЛН
Как открыть дверь в Jaecoo J8? Удобно?🤔😊
0:27
Суворкин Сергей
Рет қаралды 1 МЛН
Распаковал Xiaomi SU7
0:59
Wylsacom
Рет қаралды 328 М.