Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"The owner of the fetched association was not present in the select list" error on SimpleJpaRepository#getCountQuery #3765

Open
marcioggs opened this issue Feb 7, 2025 · 1 comment
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@marcioggs
Copy link

Hi.

I'm having the error in the stack trace below using sprint-data-jpa 3.4.2 when calling JpaSpecificationExecutor#findAll(@Nullable Specification spec, Pageable pageable).

The specification being passed as an argument contains a fetch join (such as root.fetch(Entity_.attribute, JoinType.LEFT)).
The exception is thrown by SimpleJpaRepository#getCountQuery(@Nullable Specification<S> spec, Class<S> domainClass) when the entity manager tries to create the query.

Should the getCountQuery method remove the fetch from fetch joins before requesting the entity manager to create the query?

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.query.SemanticException: Query specified join fetching, but the owner of the fetched association was not present in the select list [SqmListJoin(eu.europa.ec.grow.enorm.entity.EsoProjectDetail(405).deliverableMappings(406))]
	at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:371) ~[spring-orm-6.2.2.jar:6.2.2]
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246) ~[spring-orm-6.2.2.jar:6.2.2]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:560) ~[spring-orm-6.2.2.jar:6.2.2]
	at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-6.2.2.jar:6.2.2]
	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:343) ~[spring-tx-6.2.2.jar:6.2.2]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:160) ~[spring-tx-6.2.2.jar:6.2.2]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.2.2.jar:6.2.2]
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:165) ~[spring-data-jpa-3.4.2.jar:3.4.2]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.2.2.jar:6.2.2]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223) ~[spring-aop-6.2.2.jar:6.2.2]
	at jdk.proxy3/jdk.proxy3.$Proxy267.findAll(Unknown Source) ~[na:an]

It seems to be related to issue 2348.

Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 7, 2025
@mp911de
Copy link
Member

mp911de commented Feb 10, 2025

Please provide a minimal yet complete sample that reproduces the problem.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

JPA's Criteria API doesn't allow removing fetch joins, the CriteriaBuilder is only additive in its nature. With Spring Data JPA 3.5 we're introducing a method to provide a count specification, see #3727.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants