It is not mentioned in the other answers but it is fine to use both. In my App I use JPA and JdbcTemplate, for crud type operations I use JPA but for reporting or where it is easier I use jdbcTemplate.
@Repository
public class FooRepository
{
@PersistenceContext
private EntityManager entityManager;
@Autowired(required = true)
private JdbcTemplate jdbcTemplate;
public void saveFoo(Foo foo)
{
this.entityManager.persist(foo);
}
public List getSomeReport()
{
return this.jdbcTemplate.queryForList("SELECT .. ",SomeProjectPojo.class);
}
}
The great thing about Spring is that the exception translation from JPA exceptions to spring Dao exception hierarchy works with both JPA and jdbcTemplate. So use JPA when it makes sense and jdbcTemplate when it makes sense.