Route JPAInsertClause.execute() through native SQL when values contain function templates (#1757)#1758
Open
zio0911 wants to merge 1 commit into
Open
Conversation
…n function templates (OpenFeign#1757) Detect TemplateExpression values via a shared hasTemplateValue() helper and route execute() to JpaNativeInsertSerializer + JDBC executeUpdate when present, falling back to the existing JPQL path otherwise. Same change applied to HibernateInsertClause. Adds executeUpdate(Connection, String, Object[]) to JpaInsertNativeHelper and regression tests covering both routing branches. Closes OpenFeign#1757
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
JPAInsertClause.execute()andHibernateInsertClause.execute()now route throughJpaNativeInsertSerializer(native SQL) when value expressions contain aTemplateExpression— typically a schema-qualified function call fromSQLExpressions.function/stringFunction/numberFunctionor a raw SQL fragment. Plain path/literal/parameter INSERTs continue to use the existingJPQLSerializerpath so JPA semantics (cascade behaviour for paths, callbacks where applicable) are preserved.Aligns
execute()with the native routing thatexecuteWithKey() / executeWithKeys()(#1693) already use, so callers no longer need to invoke a key-returning method purely to dodge the JPQL parser when their values contain function templates.Fixes #1757.
Changes
JPAInsertClause.execute()— detect template values via a newhasTemplateValue()helper and dispatch to native path when present, falling back to JPQL otherwise.HibernateInsertClause.execute()— same change applied withSession.doReturningWork(...)instead ofEntityManager.unwrap.JpaInsertNativeHelper— addedexecuteUpdate(Connection, String, Object[])for the non-key-returning native path. Class javadoc generalized.JPAExecuteWithKeyTestandHibernateExecuteWithKeyTest:execute_with_function_template_routes_through_native_sql— verifies thatupper({0})inside a value expression is preserved and the function is evaluated by the DB.execute_without_template_uses_jpql_path— verifies plain INSERTs still go through JPQL.Test plan
./mvnw -Pdev -pl querydsl-libraries/querydsl-jpa -am test— 3238 tests, 0 failuresJPAExecuteWithKeyTest(13 tests, includes 2 newexecute_*cases)HibernateExecuteWithKeyTest(includes 2 newexecute_*cases)INSERTwith a schema-qualified external SQL function — pre-patch reproduced theSemanticExceptionfrom JPAInsertClause.execute() does not route to native SQL when values contain function templates / SQL fragments #1757; post-patch the INSERT succeeds via the native path.