Skip to content

Conversation

academey
Copy link

Fixes #3979

#{#entityName} was returning entity name instead of table name for native queries, causing failures with SELECT *.

Changes:

  • Add getTableName() to JpaEntityMetadata interface
  • Return table name for native queries, entity name for JPQL queries
  • Add test case

…name

Fixes spring-projects#3979

Native queries with SELECT * and #{#entityName} were failing because #{#entityName} was returning the entity name instead of the table name for native queries.

This change:
- Adds getTableName() method to JpaEntityMetadata interface with default implementation
- Makes #{#entityName} return table name for native queries and entity name for JPQL queries
- Removes instanceof checks for cleaner, type-safe code

Added test to verify the fix works correctly.

Signed-off-by: academey <[email protected]>
@academey academey force-pushed the fix/3979-native-query-spel-regression branch from b81c04a to c811561 Compare August 20, 2025 15:07
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 20, 2025
@mp911de
Copy link
Member

mp911de commented Aug 25, 2025

This is not a fix but rather introduction of new functionality. That isn't going to make the cut here as Hibernate uses a PhysicalNamingStrategy to transform table and column names. There's also no meta-model exposure of table names.

@mp911de mp911de closed this Aug 25, 2025
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 25, 2025
@academey
Copy link
Author

Thanks for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExpressionBasedStringQuery does not expand #{#entityName} for native queries
3 participants