Skip to content

Generated JPQL uses non-standard fully-qualified entity names #4032

@jim-jobcase

Description

@jim-jobcase

I have an internal application currently on Spring Boot 3.5.6 and Hibernate 6.6.29, which I'm trying out on Spring Boot 4.0.0-M3 with Hibernate 7.1.2. I have confirmed that I am running with Spring Data JPA 4.0.0-M6.

Our application has the Hibernate option hibernate.jpa.compliance set, which enables stricter checks on JPQL content. In our application we have a repository interface class defined, which extends CrudRepository and PagingAndSortingRepository. When Spring Data JPA runs, it allocates a org.springframework.data.jpa.repository.query.JpqlQueryBuilder.Entity object, which includes content like this:

entity: com.myorg.app.model.Foo
simpleName: Foo
alias: f

We call a repository method that generates a SELECT and ultimately wind up in org.springframework.data.jpa.repository.jpa.JpqlQueryBuilder.Select on lines 849-850:

StringBuilder result = new StringBuilder(
		"SELECT %s FROM %s %s".formatted(selection.render(renderContext), entity.getEntity(), entity.getAlias()));

This generates the SQL:

SELECT f FROM com.myorg.app.model.Foo f

The SQL is passed along until it enters Hibernate and gets to org.hibernate.query.hql.internal.SemanticQueryBuilder. checkFQNEntityNameJpaComplianceViolationIfNeeded on line 6173. Here it checks that the entity in the query matches the name of the entity descriptor, which unfortunately it does not - the name value into this function is com.myorg.app.model.Foo while entityDescriptor.jpaEntityName is Foo, triggering an exception that fails the query.

To my eyes, it seems like the StringBuilder creation above should use entity.getName() instead of entity.getEntity() such that the Hibernate checks should pass. However, I also haven't found any documentation in Spring Data JPA saying that the Hibernate JPA compliance option is supported - disabling the setting does also fix the issue by suppressing the check.

Is this a code bug, or is the option not supported with Spring Data JPA? Or do you believe Hiberate has erred in their interpretation of the JPA spec?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions