Java 我使用@query和Pageable进行的自定义查询可以正常工作,但不能';t返回结果
我有一个疑问:Java 我使用@query和Pageable进行的自定义查询可以正常工作,但不能';t返回结果,java,sql,spring-data-jpa,Java,Sql,Spring Data Jpa,我有一个疑问: public interface IProductoDao extends PagingAndSortingRepository<Producto, Long> { @Query(value = "select * from productos p where p.nombre like %?1% and p.categoria = ?2", countQuery = "select count(*) f
public interface IProductoDao extends PagingAndSortingRepository<Producto, Long> {
@Query(value = "select * from productos p where p.nombre like %?1% and p.categoria = ?2",
countQuery = "select count(*) from productos p where p.nombre like %?1% and p.categoria = ?2",
nativeQuery = true)
public Page<Producto> findByNombreAndCategoria(String term, String cat, Pageable pageable);
}
我不明白查询返回了什么。我认为查询应该返回类似PagingAndSortingRepository接口的本机方法(findAll(Pageable page)):
@Override
@Transactional(readOnly = true)
public Page<Producto> findAll(Pageable pageable) {
return productoDao.findAll(pageable);
}
感谢您的时间和帮助。您确定使用本机查询吗?是的,因为when's not work会抛出错误。
@Override
@Transactional(readOnly = true)
public Page<Producto> findAll(Pageable pageable) {
return productoDao.findAll(pageable);
}
2021-04-03 23:49:01.506 DEBUG 19724 --- [nio-8080-exec-4] org.hibernate.SQL : select producto0_.id as id1_0_, producto0_.categoria as categori2_0_, producto0_.descripcion as descripc3_0_, producto0_.imagenes as imagenes4_0_, producto0_.nombre as nombre5_0_, producto0_.precio as precio6_0_ from productos producto0_ limit ?
2021-04-03 23:49:01.509 DEBUG 19724 --- [nio-8080-exec-4] org.hibernate.SQL : select count(producto0_.id) as col_0_0_ from productos producto0_
Productos: Page 1 of 6 containing com.abril.tiendaonline.app.models.entity.Producto instances