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>
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 TypeMethodDescriptionvoiddeleteByName(String name) Deletes a product by its name.findByBrand(String brand) Finds a product by its brand name.findByName(String 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, 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
-
findByName
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
Optionalcontaining the matchingProductif found, orOptional.empty()if no product has this name
-
findByBrand
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
Optionalcontaining the first matchingProduct, orOptional.empty()if none found. For multiple results, consider usingList<Product> findAllByBrand(String brand)
-
deleteByName
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
-