Interface CategoryRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<Category,Long>, org.springframework.data.jpa.repository.JpaRepository<Category,Long>, org.springframework.data.repository.ListCrudRepository<Category,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<Category,Long>, org.springframework.data.repository.PagingAndSortingRepository<Category,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<Category>, org.springframework.data.repository.Repository<Category,Long>

@Repository public interface CategoryRepository extends org.springframework.data.jpa.repository.JpaRepository<Category,Long>
Spring Data JPA repository for Category entities.

Provides standard CRUD operations inherited from JpaRepository and custom query methods for category-specific lookups.

Categories are used to organize products into logical groups (e.g., "Electronics", "Clothing", "Books"). The name field is unique across the system, making it a natural key for fast lookups.

This repository is automatically implemented by Spring at runtime using proxy-based mechanism — no manual implementation required.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Finds a category by its exact name (case-sensitive).

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByName

      Optional<Category> findByName(String name)
      Finds a category by its exact name (case-sensitive).

      Since category names are unique in the system, this method returns at most one result wrapped in an Optional.

      Typical use cases:

      • Checking if a category already exists before creating a new one
      • Retrieving a category for product assignment during creation/update
      • Admin panel operations (edit, delete, view products in category)
      • URL-friendly slugs or navigation menu generation

      Parameters:
      name - the exact name of the category to search for (not null, not blank)
      Returns:
      an Optional containing the matching Category if found, or Optional.empty() if no category with this name exists