Spring Data configuration

As we learned in the introduction, Spring Data provides a common approach to connect different data stores. Spring Data provides basic abstraction through the Repository interface. The Repository interface is the core interface of Spring Data. Basic repositories provided by Spring Data are as follows:

  • CrudRepository provides basic CRUD operations
  • PagingAndSortingRepository provides methods to do the pagination and sorting of records
  • JpaRepository provides JPA-related methods, such as flush and insert/update/delete in a batch, and so on

Repository, in Spring Data, eliminates the implementation of DAOs and templates such as HibernateTemplate or JdbcTemplate. Spring Data is so abstract that we don't even need to write any method implementation for basic CRUD operations; we just need to define interfaces based on Repository and define proper naming conventions for methods. Spring Data will take care of creating a query based on a method name, and execute it to a database.

The Java configuration for Spring Data remains the same as what we saw for the Spring JPA, using Hibernate, except for the addition of defining repositories. The following is a snippet of declaring repositories to the configuration:

@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-hibernate.properties" })
@ComponentScan({ "com.packt.springhighperformance.ch6.bankingapp" })
@EnableJpaRepositories(basePackages = "com.packt.springhighperformance.ch6.bankingapp.repository")
public class PersistenceJPAConfig {

}

In this chapter, we are not going to dive too deeply into Hibernate and Spring Data-specific development. However, we will dive into the problems faced when not using Hibernate or JPA optimally and with the right configuration in our application, and solutions to the problems, with the best practices to achieve high performance. Let's look at the common Hibernate problems we face when using it in our applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset