Fix invalid JPQL emitted by JPAInsertClause set() style (#1718)#1719
Open
zio0911 wants to merge 1 commit into
Open
Fix invalid JPQL emitted by JPAInsertClause set() style (#1718)#1719zio0911 wants to merge 1 commit into
zio0911 wants to merge 1 commit into
Conversation
JPQLSerializer.serializeForInsert was emitting `path = value` pairs
for the set()-style inserts map, producing invalid JPQL like:
insert into Cat (name, alive)
cat.name = ?1, cat.alive = ?2
Hibernate rejected this with SyntaxException because JPQL/HQL only
supports the VALUES form (and INSERT ... SELECT) — there is no SET
form for INSERT.
Convert the inserts map to a VALUES (...) list using the same
iteration order as the column list (LinkedHashMap), producing valid:
insert into Cat (name, alive)
values (?1, ?2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1718.
JPAInsertClause/HibernateInsertClause.set(path, value)calls were producing invalid JPQL (path = valuepairs after the column list) which Hibernate rejected withSyntaxException. The serializer now emits a properVALUES (...)clause for theinsertsmap, matching the existing column list order (LinkedHashMap).Before
→
org.hibernate.query.SyntaxException: At 2:0 and token 'cat', mismatched input 'cat', expecting one of the following tokens: '(', FROM, ORDER, SELECT, VALUES, WHERE, WITHAfter
Scope
JPQLSerializer.serializeForInsert— converts theinsertsmap to aVALUESlist instead ofpath = valuepairscolumns().values()style andINSERT ... SELECT(sub-query) paths are unchangedTest plan
JPQLSerializerTest:serializeForInsert_setStyle_emitsValuesForm— verifiesset()-style now emitsVALUES (...)and nopath = valueserializeForInsert_columnsValuesStyle_unchanged— guards thecolumns().values()path./mvnw -pl querydsl-libraries/querydsl-jpa -Pno-databases test— 368 tests pass