简体   繁体   English

MySQL存储过程与JPA查询

[英]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. 我目前正在开发一个Java Web项目,我必须选择具有所有ORM内容的JPA,并且有机会使用存储过程直接或直接MySQL查询来设置查询。 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? 存储过程是否比JPA查询更快?

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. 通常,使用JPA,在性能调优方面,您实施自定义解决方案的控制要少得多。 However, JPA provides a solid, proven infrastructure with a boat load of functionality that you don't have to write yourself! 但是,JPA提供了一个可靠且经过验证的基础架构,其中包含一系列功能,您无需自行编写! JPA will definitely help you to more quickly get your application off the ground. JPA肯定会帮助您更快地启动应用程序。

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. 两者都需要SQL和实体关系模型的工作知识。 The JPA approach requires you learn JPA! JPA方法要求你学习JPA! Go figure! 去搞清楚! A MySQL approach requires knowledge of JDBC. MySQL方法需要JDBC知识。

Your question, 'do stored procedure run faster than JPA queries' is not really the right question to ask. 您的问题“存储过程比JPA查询运行得更快”并不是一个值得提出的问题。 JPA 2.1 supports stored procedures. JPA 2.1支持存储过程。 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. 更好的问题是,JPA中的查询是否比JDBC调用的MySQL查询运行得更快,或者JPA中的存储过程运行得比JDBC调用的MYSQL存储过程更快。 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. 总而言之,直接JDBC方法可能比JPA快一点,但这只是因为将JPQL(JPA的类SQL语言)转换为SQL的开销很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM