Skip to content

Route JPAInsertClause.execute() through native SQL when values contain function templates (#1757)#1758

Open
zio0911 wants to merge 1 commit into
OpenFeign:masterfrom
zio0911:fix/jpa-insert-execute-native-1757
Open

Route JPAInsertClause.execute() through native SQL when values contain function templates (#1757)#1758
zio0911 wants to merge 1 commit into
OpenFeign:masterfrom
zio0911:fix/jpa-insert-execute-native-1757

Conversation

@zio0911
Copy link
Copy Markdown
Contributor

@zio0911 zio0911 commented May 26, 2026

Summary

JPAInsertClause.execute() and HibernateInsertClause.execute() now route through JpaNativeInsertSerializer (native SQL) when value expressions contain a TemplateExpression — typically a schema-qualified function call from SQLExpressions.function/stringFunction/numberFunction or a raw SQL fragment. Plain path/literal/parameter INSERTs continue to use the existing JPQLSerializer path so JPA semantics (cascade behaviour for paths, callbacks where applicable) are preserved.

Aligns execute() with the native routing that executeWithKey() / 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 new hasTemplateValue() helper and dispatch to native path when present, falling back to JPQL otherwise.
  • HibernateInsertClause.execute() — same change applied with Session.doReturningWork(...) instead of EntityManager.unwrap.
  • JpaInsertNativeHelper — added executeUpdate(Connection, String, Object[]) for the non-key-returning native path. Class javadoc generalized.
  • Regression tests in JPAExecuteWithKeyTest and HibernateExecuteWithKeyTest:
    • execute_with_function_template_routes_through_native_sql — verifies that upper({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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JPAInsertClause.execute() does not route to native SQL when values contain function templates / SQL fragments

2 participants