3. Spring Data JPA Deep Dive 3.1 Configuration (Java Config) @Configuration @EnableJpaRepositories(basePackages = "com.example.repo") @EnableTransactionManagement public class JpaConfig @Bean public DataSource dataSource() /* HikariCP etc */ @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() // JPA vendor adapter (Hibernate)
Example:
And , Or , Between , LessThan , GreaterThan , Like , Containing , OrderBy , First , Top , AllIgnoreCase , Exists . 3.4 @Query — Explicit control @Query("SELECT u FROM User u WHERE u.email = :email") User findByEmail(@Param("email") String email); // Native SQL @Query(value = "SELECT * FROM users u WHERE u.status = 1", nativeQuery = true) List<User> findAllActive(); 3.5 Modifying queries + transactions @Modifying @Transactional @Query("UPDATE User u SET u.active = false WHERE u.lastLogin < :date") int deactivateInactiveUsers(@Param("date") LocalDate date); 4. Auditing – Automatic Timestamps @Entity public class User @CreatedDate private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; spring data spring data packt .pdf checked
Example:
Repository (marker) ├── CrudRepository<T, ID> ├── PagingAndSortingRepository<T, ID> └── JpaRepository<T, ID> (JPA-specific) 3.3 Query Derivation — The Magic Method name → JPQL query automatically. Auditing – Automatic Timestamps @Entity public class User
I cannot directly retrieve or check the contents of that specific PDF file. However, I provide a comprehensive, deep technical guide covering the key topics typically found in Packt’s Spring Data books (e.g., Spring Data: Modern Data Access for Enterprise Java or similar titles). // In repo: List<
// In repo: List<UserSummary> findByLastName(String last); @DataJpaTest @AutoConfigureTestDatabase(replace = Replace.NONE) // use real DB if needed class UserRepoTest @Autowired private TestEntityManager entityManager; @Autowired private UserRepo repo; @Test void shouldFindByEmail() User user = new User("test@example.com"); entityManager.persist(user); Optional<User> found = repo.findByEmail("test@example.com"); assertThat(found).isPresent();