• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA vs Home Grown JDBC Wrappers

 
Raja Gullapalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Ive been through several of the posts in this forum on the performance advantages of JPA, over several other
technologies. But, I still have a doubt on specific things, which is why I'm posting this question.

I've been trying to implement a performance exhaustive application which needs to load data from tables, to a
local cache. And, also provide interfaces to load directly to POJO's.

I've had this debate several times with my colleagues on whether loading/writing data from/to tables would be faster
with JPA compliant providers like eclipse link or having write JDBC SQL queries.

Thanks,
Raja
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there is a lot to it. And in many cases you can make JPA faster than JDBC, and in many cases you can make JPA much slower than JDBC. It all depends on your knowledge and willing to look things up when JPA is slower. My motto, is "Friends don't let friends code JDBC" Now with things like SPring's JdbcTemplate your life is so much easier, but you still don't get the added benefits of JPA.

Benefits
1) Automatic change detection. No longer do you need to write that code to figure out it you need an insert or an update and still have to code both queries. In JPA just call persist() and let JPA figure it out for you.
2) Caching. First Level cache is automatic. Have an EntityManager and load some data, then need to load some more in which that data is already managed by the EntityManger, great, JPA will not go to the database and save you a round trip. JDBC just cannot do this, every time you need data, you have to do a database call.


3) Second level caching. You can use this for either JDBC or JPA, so you can't totally give an advantage to either side.

Other notes, sometimes a query still needs to be SQL and JPA and JDBC can run SQL.

4) With JDBC you end up writing lots of error prone adapter classes to map your Resultsets to you Java domain objects.

My 2 cents

Mark
 
Raja Gullapalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark,

I've been workig on JPA for a year now, and I never really thought about the big picture of performance issues.
I always thought for smaller applications JDBC could be faster. But for applications with huge data
and when running on performance bottle neck application JPA would be a better choice as the overhead
that adds upon during scaling is minute compared to JDBC scaling.

Do you agree on that? I have a performance intensive application that stores all data in memory using
the JBoss cache. One of my concerns is that adding JPA, will it be a huge overhead than the currently being used
home grown JDBC wrappers.

Performance is the main criteria.

Thanks,
Raja
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought this was an interesting point, recently made in the JBoss Hibernate forums:

What most people forget, when asking this sort of question is, that Hibernate has caching at multiple layers with support for a number of caching models. Hibernates caching architecture can, and more often will, result in hibernate being faster than direct JDBC. Now this is not necessarily a fair comparison. Though caching techniques in theory are easy, in practice its hard so adding caching to direct JDBC layer is very difficult to get obsoletely right. Hence it is an engineering issue where you need to balance and consider many issues.


https://forum.hibernate.org/viewtopic.php?f=1&t=999189&p=2416951&hilit=performance#p2416951

-Cameron McKenzie
 
Raja Gullapalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's nice to know.

Thank you,
Raja
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic