我已经使用创建了一个网关应用mysql 8.0.25
程序jhipster 7.1.0
我想进行 1 次查询以通过 user_id 获取所有 userExam,所以我使用了
Flux<UserExam> findAllBy(Pageable pageable, Criteria criteria)
方法是内置的方法UserExamRepository
。
我像这样使用它
userExamRepository.findAllBy(pageable, Criteria.where("user_id").is(userId))
但我有一个错误
nested exception is io.r2dbc.spi.R2dbcBadGrammarException:
[1064] [42000] You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near
'WHERE e.user_id = '4c973896-5761-41fc-8217-07c5d13a004b'' at line 1
带有查询字符串
SELECT e.id AS e_id, e.exam_id AS e_exam_id, e.user_id AS e_user_id, exam.id AS exam_id, exam.ten_de AS exam_ten_de, e_user.id AS user_id, e_user.login AS user_login, e_user.first_name AS user_first_name, e_user.last_name AS user_last_name, e_user.email AS user_email, e_user.activated AS user_activated, e_user.lang_key AS user_lang_key, e_user.image_url AS user_image_url
FROM user_exam e
LEFT OUTER JOIN exam exam ON e.exam_id = exam.id
LEFT OUTER JOIN jhi_user e_user ON e.user_id = e_user.id
LIMIT 0, 20
WHERE e.user_id = '4c973896-5761-41fc-8217-07c5d13a004b'
我认为这个查询在语法上不正确。
正确的语法应该是... WHERE... LIMIT 0, 20
所以我在EntityManager.createSelect(...)
方法上做了一点改动:
public String createSelect(SelectFromAndJoinCondition selectFrom, Class<?> entityType, Pageable pageable, Criteria criteria) {
if (pageable != null) {
if (criteria != null) {
return createSelectImpl(
selectFrom.where(Conditions.just(criteria.toString())),// remove limitOffset
entityType,
pageable.getSort()
);
} else {
return createSelectImpl(
selectFrom.limitOffset(pageable.getPageSize(), pageable.getOffset()),
entityType,
pageable.getSort()
);
}
} else {
if (criteria != null) {
return createSelectImpl(selectFrom.where(Conditions.just(criteria.toString())), entityType, null);
} else {
return createSelectImpl(selectFrom, entityType, null);
}
}
}
它不返回错误,但我仍然想使用where
and limit
。
请帮帮我!
感谢收看