Interface ReviewRepository

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

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

Provides full CRUD operations inherited from JpaRepository and rich query methods optimized for review management, moderation, and display in the product catalog and customer profiles.

Reviews are user-generated content linking a Customer to a Product with a rating (1–5) and optional text. Efficient access by customer, product, or login is essential for:

  • Displaying reviews on product pages
  • Showing "My Reviews" section in customer profile
  • Admin moderation tools
  • Calculating average product ratings

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 all reviews associated with a given product.
    void
    Deletes all reviews for a product identified by its name.
    Finds all reviews written by a specific customer.
    Finds all reviews written by a customer identified by their login.
    Finds all reviews for a specific product.
    Finds all reviews for a product by its name.

    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

    • findByCustomer

      List<Review> findByCustomer(Customer customer)
      Finds all reviews written by a specific customer.

      Used in the customer profile ("My Reviews") and for reputation/engagement analytics.

      Parameters:
      customer - the customer who wrote the reviews (must not be null)
      Returns:
      a list of reviews by this customer (may be empty)
    • findByCustomerLogin

      List<Review> findByCustomerLogin(String login)
      Finds all reviews written by a customer identified by their login.

      Useful when only the login is known (e.g., from authentication context) and full Customer entity is not loaded.

      Parameters:
      login - the customer's login/username
      Returns:
      a list of reviews written by the customer with this login
    • findByProduct

      List<Review> findByProduct(Product product)
      Finds all reviews for a specific product.

      Primary method for displaying reviews on product detail pages and calculating average rating and review count.

      Parameters:
      product - the product being reviewed (must not be null)
      Returns:
      a list of all reviews for this product (ordered by date descending by default)
    • findByProductName

      List<Review> findByProductName(String name)
      Finds all reviews for a product by its name.

      Convenient when the Product entity is not loaded, but the name is known (e.g., from URL slug or search).

      Parameters:
      name - the exact product name
      Returns:
      a list of reviews for the product with this name
    • deleteByProduct

      void deleteByProduct(Product product)
      Deletes all reviews associated with a given product.

      Used when a product is permanently removed from the catalog. Typically called within a service that handles cascading deletion.

      Warning: This is a destructive operation affecting user-generated content. Consider soft-delete, archiving, or anonymization instead.

      Parameters:
      product - the product whose reviews should be deleted
    • deleteByProductName

      void deleteByProductName(String name)
      Deletes all reviews for a product identified by its name.

      Convenience method for batch operations when only the product name is available.

      Parameters:
      name - the name of the product whose reviews should be deleted