【发布时间】:2021-08-10 00:23:49
【问题描述】:
当我尝试做的时候, 这有效并返回给我一个列表
@Repository{
public interface CustomerRepository extends JPARepository<CustomerEntity,Long>{
@Query("select c from Customer c where c.custName LIKE %:custName% ORDER BY AGE DESC"
List<CustomerEntity> fetchAllCustomer(String custname);
}
但是当我尝试这样做时: result1 --> 返回一个列表, 结果 2 --> 错误 : java.lang.illegealArguments: org.hibernate.gql.internal.QuerySyntaxException: 意外令牌 : % near line 1 , column 112
public class CustomerResolver implements GraphQlQueryResolver{
@PersistaneUnit
private EntityManagerFactory emf;
public List<CustomerType> findCustomer(String search){
EntityManager em = emf.createEntityManager();
List<CustomerType> result1 = (List<CustomerType>)em.createQuery("select c from Customer c ORDER BY AGE
DESC").setMAXResults(3).getResultList();
System.out.println(result1);
List<CustomerType> result2 = (List<CustomerType>)em.createQuery("select c from Customer c where
c.custName LIKE %:custName% ORDER BY AGE
DESC").setParameter("custName",search).setMAXResults(3).getResultList();
System.out.println(result2);
...code
...code
...return ...
}
}
是否 createQuery 不占用 LIKE 的 % ,但确实适用于 @Query??????? 还是我错过了什么???
亲切的问候, 卡西斯
【问题讨论】:
标签: oracle spring-boot jpa graphql