code Connection Open Close Statement Create ResultSet Loop through POJO mapping Lots and lots of try catch, including catch in the try or the finally (don’t forget the finally !!!) Spring JDBC templates Less code Still had to go through ResultSet
to access data layer providing a JPA provider Hibernate EclipseLink OpenJPA … JPA Query language (JPQL) Focus on mappings and relationships What is it not ? Adressing boilerplate code getters and setters on your entities EntityManagerFactory.getTransaction.begin(), persist(), commit() and close() Lots of try ctach …
a JPA provider a big huge thing with lots of things to learn What is it ? A promise : a way to improve the implementation of your data access layer, writing less code. A project built on top of Spring Data. Spring Data MongoDB Spring Data Rest Spring for Hadoop … What do you need ? 2 jars : spring-data-jpa (latest version is 1.7.2-RELEASE) spring-data-commons (latest version is 1.8.2-RELEASE) Spring JPA Entities and a JPA provider Introduction
One interface to extend : It will bring to you : Every basic CRUD methods covered at once Even the not so basic ones Sorting Pagination Lots of helpers based on reflection Yes, you can still have custom queries One magic line of code
time Scans your Spring configuration for your repositories Relies heavily on Spring Data JpaRepository extends PagingAndSortingRepository PagingAndSortingRepository extends CrudRepository CrudRepository extends Repository SimpleJpaRepository is the default implementation of JpaRepository It’s not magical … but almost
are done for you Abstraction allows you to change your relation model quite easily Pagination and sorting work out of the box Custom queries with @Query are validated at bootstrap time You cannot go live with a query that is grammatically wrong Cons Don’t forget about Spring Data if you don’t want to get tied up with JPA You might want to consider QueryDsl : Domain Specific Language. A new way way to do your queries
boilerplate code Learning curve is almost inexistant Easy Fast Helped us to structure the code 1 entity = 1 repository Coding standards (‘findxxx’ methods) ? Performances are JPA performances Hand made repositories are still possible Still had to go out of JPA for 2 specific repositories Did not use reflection based helpers Less tests All CRUD methods