Interface EventRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Event,,Long> org.springframework.data.jpa.repository.JpaRepository<@NonNull Event,,@NonNull Long> org.springframework.data.repository.ListCrudRepository<Event,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<Event,,Long> org.springframework.data.repository.PagingAndSortingRepository<Event,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<Event>,org.springframework.data.repository.Repository<Event,Long>
@Repository
public interface EventRepository
extends org.springframework.data.jpa.repository.JpaRepository<@NonNull Event,@NonNull Long>
The
EventRepository provides database access for Event entities.-
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.data.domain.Page<Event> findByEventYear(int year, org.springframework.data.domain.Pageable pageable) findByIdAndYearWithGraph(Long id, int year) Finds anEventby its ID and year with the full object graph eagerly fetched (courses, distances, and races).Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByEventYear
@Query(value="SELECT DISTINCT e FROM Event e LEFT JOIN FETCH e.courses WHERE YEAR(e.startDate) = :year ORDER BY e.startDate DESC", countQuery="SELECT COUNT(DISTINCT e) FROM Event e WHERE YEAR(e.startDate) = :year") org.springframework.data.domain.Page<Event> findByEventYear(@Param("year") int year, org.springframework.data.domain.Pageable pageable) Returns aPageofeventswhosestartDatefalls within the givenyear, ordered by their start date descending.- Parameters:
year- the year to filter events bypageable- the pagination information- Returns:
- a
Pageofeventsfor the given year, ordered by start date descending
-
findByIdAndYearWithGraph
@Query("SELECT DISTINCT e FROM Event e LEFT JOIN FETCH e.courses c LEFT JOIN FETCH c.distance LEFT JOIN FETCH c.races LEFT JOIN FETCH e.eventFiles WHERE e.id = :id AND YEAR(e.startDate) = :year") Optional<Event> findByIdAndYearWithGraph(@Param("id") Long id, @Param("year") int year) Finds anEventby its ID and year with the full object graph eagerly fetched (courses, distances, and races). This avoids N+1 queries and ensures Hibernate constructs the correct concrete subclass instances for the joined-table inheritance hierarchy ofDistance.- Parameters:
id- the event IDyear- the year to filter events by- Returns:
- the event with its associated courses, distances, and races, or empty if not found
-
findDistinctYears
@Query("SELECT DISTINCT YEAR(e.startDate) FROM Event e ORDER BY YEAR(e.startDate) DESC") List<Integer> findDistinctYears()- Returns:
- a list of distinct years in descending order
-