- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
亲爱的,我在使用 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/
我想写这样的查询:- Select u from bookmaster u order by Year(b.createDate),Month(b.createDate),day(b.createDa
例如:选择不同的新 JPQA.QueryResultObjectV1(space.name,spaceID) "+ "from Space space,Building building,Floor
例如:选择不同的新 JPQA.QueryResultObjectV1(space.name,spaceID) "+ "from Space space,Building building,Floor
我有两张 table 第一张表 - 事件第二张表 - 类别 @Entity public class Event { @Id @GeneratedValue(strategy = Generation
我在我的 DAO 中使用 entityManager。 要创建表格,我使用: String CREATE_TABLE = "CREATE TABLE if not exists cats (name
在 JPQL 中,我可以通过以下方式检索实体: query = entityManager.createQuery("select c from Category c"); List categori
我需要执行以下选择: select c.address from Customer c where lower(trim(c.name)) = :name 但是我得到以下异常: javax.persi
我无法使此查询正常工作: Query query = eManager.createQuery("select c FROM News c WHERE c.NEWSID = :id",News.cla
我在我的 msql 表列中有 Long 类型,该列表示位标记。 我需要选择为其设置了所有几个标志的对象: columnValue & flags = columnValue 我尝试: javax.pe
请查看这篇文章的末尾(找到了另一种但也不起作用的方法)。第二种方式应该是更好的方式,如果有一天它起作用的话;) 我有一个由两个多对多关系组成的实体:MainEntity 有很多 A,MainEntit
首先声明我不是数据库专家。这些东西把我搞糊涂了,但不幸的是我在工作中被迫这样做,所以我有点卡住了:-) 我试图通过在 JPQL 中工作来获得一个复杂的订单,但我一点运气都没有。 我当前的查询如下所示:
我需要将此自联接转换为 JPQL: SELECT s1.* FROM site AS s1 JOIN (SELECT site_type, MAX(last_update_date) AS LastU
如果我有一个扩展 Fruit 的类 Apple,我如何编写一个 JPQL 查询来返回所有严格意义上是 Fruits 而不是 Apples 的对象? 最佳答案 这在 JPA 2.0 中是可能的,使用 T
我正在尝试获取 Order[] 数组,其中包括未收到相关文档的所有订单。 我尝试了这个查询,它返回了正确的行数。 @Query("Select o FROM Order o INNER JOIN o
我正在尝试根据用户可以选择的可能日期列表对日期进行搜索。使用日历,我要求用户输入一个日期,然后我想获取在“data_possibile”列表中具有该日期的所有可能数据包。 这是我正在使用的查询: @N
我想构建一个 JPQL 查询来将该结构的数据映射到这个 DTO: @AllArgsConstructor class UserDTO { long userId; long countOfCo
我必须对表执行批量更新。 做一个快速的例子: UPDATE Book b SET b.amount = b.amount + 1 WHERE b IN ( :books ) 问题是 b.amount
我有以下 JPA实体: @Entity class UserClient{ @Id @GeneratedValue(strategy = GenerationType.AUTO)
我有一个实体(例如 Setting),其中包含集合(例如 Settings.languages)和另一个对象(Language 的实例)。 有没有办法选择其集合实体中包含所需属性值的所有实体?例如获取
我正在使用 spring data jpa:过滤父对象的子对象的最佳方法是什么?在我下面的例子中我想要具有事件子对象的父对象,也只想要事件子对象作为父对象的列表 @Query(select dis
我是一名优秀的程序员,十分优秀!