【发布时间】:2020-10-13 03:46:28
【问题描述】:
我是 JPA/Hibernate 和 Spring Boot 的新手,我想根据收到的参数进行动态查询。我遵循这种方法 https://www.baeldung.com/spring-data-jpa-query ,但出现错误:
Error starting ApplicationContext. ERROR --- [ restartedMain] o.s.b.SpringApplication : Application startup failedCaused by: org.springframework.data.mapping.PropertyReferenceException: No property getReglas2doNivelFiltradas found for type Reglas2doNivel!
这就是我的实现方式:
存储库:
@Repository
public interface Reglas2doNivelRepository extends JpaRepository<Reglas2doNivel, Long>, Reglas2doNivelRepositoryCustom {
@Modifying
@Query("Update Reglas1erNivel r set r.activo='N' where r.id_regla = ?1")
void desactivarRegla2doNivel(Long iRegla);
@Query("Select r from Reglas2doNivel r where r.sociedad.id_sociedad = ?1")
List<Reglas2doNivel> getReglas2doNivelBySociedad(int companyID);
}
自定义仓库界面:
public interface Reglas2doNivelRepositoryCustom {
List<Reglas2doNivel> getReglas2doNivelFiltradas(int company, List<Integer> areasId, int ordenDesde, int ordenHasta, String nemoTecnico);
}
自定义存储库实现:
public class Reglas2doNivelRepositoryCustomImpl implements Reglas2doNivelRepositoryCustom {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<Reglas2doNivel> getReglas2doNivelFiltradas(int company, List<Integer> areasId, int ordenDesde,
int ordenHasta, String nemoTecnico) {
return null;
}
}
服务:
@Override
public List<Reglas2doNivel> getReglas2doNivelBySociedad(int companyID) {
return reglas2doNivelRepository.getReglas2doNivelBySociedad(companyID);
}
怎么了?
谢谢
【问题讨论】:
-
您没有遵循正确的约定。未检测到自定义实现,因此它将尝试从该方法进行查询(失败)。确保名称与接口名称 +
Impl完全相同,并且两个文件都在同一个包中,而不是不同的包中!。 -
嗨,谢谢你的回答,我不明白你的意思。名称是: Reglas2doNivelRepositoryCustomImpl 和 Reglas2doNivelRepositoryCustom ,所以是相同的 +Impl。什么叫错了?
-
它们也必须在同一个包中。
-
是的,它们在同一个包中,三个存储库
标签: java spring spring-boot hibernate jpa