Package com.proyecto.jpa.repository
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>
Repositorio JPA para la entidad Category.
JpaRepository proporciona operaciones CRUD automáticas:
- save(S entity): guarda una entidad
- findById(ID id): busca por ID
- findAll(): obtiene todas las entidades
- deleteById(ID id): elimina por ID
- count(): cuenta el número de entidades
También se pueden definir consultas personalizadas usando
la convención de nombres de métodos de Spring Data JPA.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanexistsByName(String name) Verifica si existe una categoría con el nombre dado.findByName(String name) Busca una categoría por su nombre.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
Busca una categoría por su nombre. Spring Data JPA genera automáticamente la consulta: SELECT * FROM categories WHERE name = ?- Parameters:
name- nombre de la categoría- Returns:
- Optional con la categoría si existe
-
existsByName
Verifica si existe una categoría con el nombre dado.- Parameters:
name- nombre de la categoría- Returns:
- true si existe, false en caso contrario
-