gpt4 book ai didi

java - JPQL查询异常异常AST节点: {vector}

转载 作者:行者123 更新时间:2023-12-01 23:01:58 25 4
gpt4 key购买 nike

亲爱的,我在使用 JPQL 查询时遇到问题,当我使用 IN 和列表(长)时,我收到错误,但并非总是如此

this is the model(是查看关系的最小模型,没有所有列)

如果我在 mi repo 中执行此查询工作正常:

@Query(value = "SELECT a FROM Artist a WHERE a.idArtist IN(SELECT a.idArtist FROM ArtistStyle x "
+ "INNER JOIN x.style s "
+ "INNER JOIN x.artist a "
+ "WHERE s.idStyle IN (:arrayStyles))")
public List<Artist> FilterArtistWithStyles(List<Long> arrayStyles);

但是如果我执行此查询,我会得到错误:

@Query(value = "SELECT a FROM Artist a WHERE a.idArtist IN(SELECT a.idArtist FROM ArtistStyle x "
+ "INNER JOIN x.style s "
+ "INNER JOIN x.artist a "
+ "INNER JOIN a.country c "
+ "INNER JOIN a.aal1 a1 "
+ "INNER JOIN a.aal2 a2 "
+ "INNER JOIN a.aal3 a3 "
+ "WHERE (:arrayStyles IS NULL OR s.idStyle IN (:arrayStyles)) "
+ "AND (:name IS NULL OR a.name like %:name%)" + "AND (:gender IS NULL OR a.gender = :gender) "
+ "AND (:experienceFrom IS NULL OR a.workStartYear <= :experienceFrom) "
+ "AND (:ratingFrom IS NULL OR a.ratingAccordance >= :ratingFrom) "
+ "AND (:delivery IS NULL OR a.delivery = :delivery) "
+ "AND (:exchange IS NULL OR a.exchange = :exchange) " + "AND (:courses IS NULL OR a.courses = :courses)"
+ "AND (:idCountry IS NULL OR c.idCountry = :idCountry)"
+ "AND (:idAal1 IS NULL OR a1.idAdministrativeAreaLevel1 = :idAal1)"
+ "AND (:idAal2 IS NULL OR a2.idAdministrativeAreaLevel2 = :idAal2)"
+ "AND (:idAal3 IS NULL OR a3.idAdministrativeAreaLevel3 = :idAal3)" + ")")
public List<Artist> SearchArtistWithStyles(String name, List<Long> arrayStyles, Integer gender, Integer experienceFrom, Double ratingFrom, Integer delivery,
Integer exchange, Integer courses, Long idCountry, Long idAal1, Long idAal2, Long idAal3,
Pageable pageable);

这是错误:

"status": 500,
"error": "Internal Server Error",
"message": "org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} [SELECT a FROM com.mushroomstudios.skink.entities.Artist a WHERE a.idArtist IN(SELECT a.idArtist FROM com.mushroomstudios.skink.entities.ArtistStyle x INNER JOIN x.style s INNER JOIN x.artist a INNER JOIN a.country c INNER JOIN a.aal1 a1 INNER JOIN a.aal2 a2 INNER JOIN a.aal3 a3 WHERE (:arrayStyles_0, :arrayStyles_1, :arrayStyles_2 IS NULL OR s.idStyle IN (:arrayStyles_0, :arrayStyles_1, :arrayStyles_2)) AND (:name IS NULL OR a.name like :name)AND (:gender IS NULL OR a.gender = :gender) AND (:experienceFrom IS NULL OR a.workStartYear <= :experienceFrom) AND (:ratingFrom IS NULL OR a.ratingAccordance >= :ratingFrom) AND (:delivery IS NULL OR a.delivery = :delivery) AND (:exchange IS NULL OR a.exchange = :exchange) AND (:courses IS NULL OR a.courses = :courses)AND (:idCountry IS NULL OR c.idCountry = :idCountry)AND (:idAal1 IS NULL OR a1.idAdministrativeAreaLevel1 = :idAal1)AND (:idAal2 IS NULL OR a2.idAdministrativeAreaLevel2 = :idAal2)AND (:idAal3 IS NULL OR a3.idAdministrativeAreaLevel3 = :idAal3)) order by a.name asc]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} [SELECT a FROM com.mushroomstudios.skink.entities.Artist a WHERE a.idArtist IN(SELECT a.idArtist FROM com.mushroomstudios.skink.entities.ArtistStyle x INNER JOIN x.style s INNER JOIN x.artist a INNER JOIN a.country c INNER JOIN a.aal1 a1 INNER JOIN a.aal2 a2 INNER JOIN a.aal3 a3 WHERE (:arrayStyles_0, :arrayStyles_1, :arrayStyles_2 IS NULL OR s.idStyle IN (:arrayStyles_0, :arrayStyles_1, :arrayStyles_2)) AND (:name IS NULL OR a.name like :name)AND (:gender IS NULL OR a.gender = :gender) AND (:experienceFrom IS NULL OR a.workStartYear <= :experienceFrom) AND (:ratingFrom IS NULL OR a.ratingAccordance >= :ratingFrom) AND (:delivery IS NULL OR a.delivery = :delivery) AND (:exchange IS NULL OR a.exchange = :exchange) AND (:courses IS NULL OR a.courses = :courses)AND (:idCountry IS NULL OR c.idCountry = :idCountry)AND (:idAal1 IS NULL OR a1.idAdministrativeAreaLevel1 = :idAal1)AND (:idAal2 IS NULL OR a2.idAdministrativeAreaLevel2 = :idAal2)AND (:idAal3 IS NULL OR a3.idAdministrativeAreaLevel3 = :idAal3)) order by a.name asc]",

最后,如果我执行该查询,也可以正常工作:

@Query(value = "SELECT a FROM Artist a " + "INNER JOIN a.country c " 
+ "INNER JOIN a.aal1 a1 "
+ "INNER JOIN a.aal2 a2 "
+ "INNER JOIN a.aal3 a3 "
+ "WHERE (:name IS NULL OR a.name like %:name%) "
+ "AND (:gender IS NULL OR a.gender = :gender) "
+ "AND (:experienceFrom IS NULL OR a.workStartYear <= :experienceFrom) "
+ "AND (:ratingFrom IS NULL OR a.ratingAccordance >= :ratingFrom) "
+ "AND (:delivery IS NULL OR a.delivery = :delivery) "
+ "AND (:exchange IS NULL OR a.exchange = :exchange) " + "AND (:courses IS NULL OR a.courses = :courses)"
+ "AND (:idCountry IS NULL OR c.idCountry = :idCountry)"
+ "AND (:idAal1 IS NULL OR a1.idAdministrativeAreaLevel1 = :idAal1)"
+ "AND (:idAal2 IS NULL OR a2.idAdministrativeAreaLevel2 = :idAal2)"
+ "AND (:idAal3 IS NULL OR a3.idAdministrativeAreaLevel3 = :idAal3)")
public List<Artist> SearchArtist(String name, Integer gender, Integer experienceFrom, Double ratingFrom,
Integer delivery, Integer exchange, Integer courses, Long idCountry, Long idAal1, Long idAal2, Long idAal3,
Pageable pageable);

第二个查询有什么问题吗?如果您需要更多信息,例如实体或其他信息,请告诉我,提前致谢

最佳答案

问题出在这一行

 "WHERE (:arrayStyles IS NULL OR s.idStyle IN (:arrayStyles)) "

我更改为,并且工作正常

+ "WHERE s.idStyle IN (:arrayStyles) "

关于java - JPQL查询异常异常AST节点: {vector},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58416770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com