Search code examples
javajpajdbcmixing

Is it OK to use both JPA (for normal CRUDs) and JDBC (for batch update & call stored proc) in the same project


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).

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.

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


Solution

  • It's OK. However you should ensure that you invalidate relevant JPA caches when you make direct JDBC batch updates.

    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.