Interface ProductRepository

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

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

Provides full CRUD functionality inherited from JpaRepository and custom query methods optimized for product catalog management and search.

Products are the core sellable items in the shop. Fast lookup by name and brand is essential for:

  • Admin panel operations
  • Duplicate prevention during product creation
  • Search functionality and filtering
  • Import/export and data synchronization processes

This repository is automatically implemented by Spring at runtime — no manual implementation required.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes a product by its name.
    Finds a product by its brand name.
    Finds a product 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<Product> findByName(String name)
      Finds a product by its exact name (case-sensitive).

      Product names are typically unique within the system (or within a brand), making this method ideal for exact-match lookups.

      Used in:

      • Product creation validation (prevent duplicates)
      • Admin edit forms (load by name)
      • URL slugs / SEO-friendly URLs
      • Integration with external systems

      Parameters:
      name - the exact product name to search for
      Returns:
      an Optional containing the matching Product if found, or Optional.empty() if no product has this name
    • findByBrand

      Optional<Product> findByBrand(String brand)
      Finds a product by its brand name.

      Useful when displaying all products from a specific manufacturer or during brand-specific filtering in the catalog.

      Note: Multiple products can share the same brand.

      Parameters:
      brand - the brand name to search for (exact match)
      Returns:
      an Optional containing the first matching Product, or Optional.empty() if none found. For multiple results, consider using List<Product> findAllByBrand(String brand)
    • deleteByName

      void deleteByName(String name)
      Deletes a product by its name.

      Convenience method that removes a product without loading it first. Particularly useful in:

      • Batch cleanup scripts
      • Admin tools performing deletion by known name
      • Data migration or deduplication processes

      Warning: This is a destructive operation. Consider soft-delete patterns or cascading effects (reviews, order history) before using in production.

      Parameters:
      name - the name of the product to delete