LizardKing89
LizardKing89

Reputation: 66

MySQL Stored Procedures vs JPA Queries

I'm currently developing a Java Web Project and I have to choose either JPA with all the ORM stuff and the chance to set queries direct or direct MySQL queries with Stored Procedures. I have to consider the advantages and disadvantages of theses points in strict order:

  1. Performance: Give results fastly
  2. Complexity: Which solution has more learning curve?

Do the stored procedures are faster than JPA queries?

Upvotes: 3

Views: 3110

Answers (1)

cmd
cmd

Reputation: 11841

In terms of performance, I don't have any specific numbers. Please elaborate on specific concerns you might have.

In general, with JPA you have far less control when it comes to performance tuning than you would if implementing a custom solution. However, JPA provides a solid, proven infrastructure with a boat load of functionality that you don't have to write yourself! JPA will definitely help you to more quickly get your application off the ground.

In terms of learning curve. If I assume you are starting fresh... there is a great deal to learn with either approach. Both require a working knowledge of SQL and entity relationship models. The JPA approach requires you learn JPA! Go figure! A MySQL approach requires knowledge of JDBC.

Your question, 'do stored procedure run faster than JPA queries' is not really the right question to ask. JPA 2.1 supports stored procedures. The better question would be, does a query in JPA run faster than a JDBC invoked MySQL query or does a stored procedure in JPA run faster than a JDBC invoked MYSQL stored procedure. All in all, a direct JDBC approach may be a bit faster than JPA, but only due to the small overhead of translating JPQL (JPA's SQL-like language) to SQL.

Upvotes: 3

Related Questions