问题描述
我正在使用JPA/Hibernate调用简单的CRUD查询(创建,更新,findByXAndYAndZ ...).但是,据我所知,JPA在调用存储过程和批处理插入/更新方面并不很好,所以我考虑使用旧的JDBC来做到这一点(例如此链接: http://www.java2s.com/Code/Java/Database-SQL-JDBC/BatchUpdateInsert.htm ).
I am using JPA/Hibernate to call simple CRUD queries (create, update, findByXAndYAndZ...). However, as I know, JPA doesn't support well on calling stored procedures and batch insert/update, so I consider using old JDBC to do that (like this link: http://www.java2s.com/Code/Java/Database-SQL-JDBC/BatchUpdateInsert.htm).
我只是想知道在混合JPA和JDBC时是否会引起任何问题.希望您可以在此问题上分享一些实际经验.谢谢.
I just wonder if it causes any problems when I mixing JPA and JDBC. Hope that you may share some real-world experiences on this issue. Thanks.
更新:我已经像Behrang Saeedzadeh的建议一样尝试了Spring Batch,并且效果很好.@Others:您可以在此处查看Spring Batch的示例: http://mkyong.com /spring/spring-jdbctemplate-batchupdate-example
UPDATE:I have tried the Spring Batch like suggestion of Behrang Saeedzadeh and it worked well.@Others: you may look at the example of Spring Batch here: http://mkyong.com/spring/spring-jdbctemplate-batchupdate-example
推荐答案
可以.但是,在进行直接JDBC批更新时,应确保使相关的JPA缓存无效.
It's OK. However you should ensure that you invalidate relevant JPA caches when you make direct JDBC batch updates.
更新:顺便说一句,您可能想考虑看看Spring Batch.使用Spring Batch,可以根据需要使用JPA或JDBC进行批量更新.
UPDATE: By the way, you might want to consider having a look at Spring Batch. Using Spring Batch you can make batch updates with JPA or with JDBC if you prefer so.
这篇关于是否可以在同一项目中同时使用JPA(用于常规CRUD)和JDBC(用于批处理更新和调用存储的proc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!