Interface ShoppingCartRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<ShoppingCart, Long>,org.springframework.data.jpa.repository.JpaRepository<ShoppingCart, Long>,org.springframework.data.repository.ListCrudRepository<ShoppingCart, Long>,org.springframework.data.repository.ListPagingAndSortingRepository<ShoppingCart, Long>,org.springframework.data.repository.PagingAndSortingRepository<ShoppingCart, Long>,org.springframework.data.repository.query.QueryByExampleExecutor<ShoppingCart>,org.springframework.data.repository.Repository<ShoppingCart, Long>
ShoppingCart entities.
Provides standard CRUD operations inherited from JpaRepository
and specialized query methods for shopping cart management.
The shopping cart has a strict one-to-one relationship with Customer relationship.
Each customer has exactly one active cart at any time. This repository enables
fast retrieval and cleanup of carts by customer association.
Key use cases:
- Restoring cart contents after user login
- Displaying cart summary in header/mini-cart
- Checkout process – retrieving cart for order creation
- Scheduled cleanup of abandoned carts
- GDPR/account deletion – removing associated cart
This repository is automatically implemented by Spring at runtime — no manual implementation required.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByCustomer(Customer customer) Deletes the shopping cart associated with a specific customer.findByCustomer(Customer customer) Finds the active shopping cart for a given customer.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
-
findByCustomer
Finds the active shopping cart for a given customer.Since the cart is uniquely tied to the customer (one-to-one), this method returns at most one result.
Used in virtually every authenticated user request to load or update the cart.
- Parameters:
customer- the customer whose cart to retrieve (must not be null)- Returns:
- an
Optionalcontaining the customer'sShoppingCartif exists, orOptional.empty()if the customer has no cart (should not happen in normal flow)
-
deleteByCustomer
Deletes the shopping cart associated with a specific customer.Used during:
- Account deletion (GDPR compliance)
- Manual cart reset (e.g., "Clear cart" button)
- Admin-initiated cleanup
Important: This method also cascades deletion of all
s if properly configured in the entity (orphanRemoval = true).invalid reference
CartItem- Parameters:
customer- the customer whose cart should be deleted
-