JavaSpringlower()的类型为STRING,但参数的类型为java.lang.String

gpfsuwkq  于 2024-01-05  发布在  Spring
关注(0)|答案(2)|浏览(160)

我在JPA Repository类中使用jpql创建了一个自定义查询。如果documentText列包含:text,则该查询将简单地返回一个列表作为DocumentDTO。对于此操作,我需要执行rewrite操作。
代码:

  1. @Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
  2. "(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
  3. "FROM Document " +
  4. "WHERE LOWER(documentText) LIKE CONCAT('%', LOWER(:text), '%')")
  5. List<DocumentDTO> findByDocument(@Param("text") String text);

字符串
错误:

  1. org.hibernate.QueryException: Parameter 1 of function lower() has type STRING, but argument is of type java.lang.String


我找不到如何将java.lang.string类型转换为string。我应该这样做吗?请帮助我。我无法解决错误2天。
我尝试了这个代码,但我没有得到任何结果。

  1. @Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
  2. "(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
  3. "FROM Document " +
  4. "WHERE LOWER(documentText as string) LIKE CONCAT('%'," +
  5. "LOWER(:text as string)" +
  6. ",'%')")
  7. List<DocumentDTO> findByDocument(@Param("text") String text);

62o28rlo

62o28rlo1#

在调用findByDocument方法之前,将字符串参数“text”转换为“text”

sigwle7e

sigwle7e2#

我用这种方式解决了这个错误。

  1. @Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
  2. "(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
  3. "FROM Document " +
  4. "WHERE LOWER(" +
  5. "cast(documentText as string)" +
  6. ") LIKE CONCAT('%', LOWER(" +
  7. "cast(:text as string)" +
  8. "), '%')")
  9. List<DocumentDTO> findByDocument(@Param("text") String text);

字符串

相关问题