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

ClassCastException: cannot be cast to class com.querydsl.sql.RelationalPathBase #67

Closed
jeusdi opened this issue Sep 7, 2022 · 2 comments

Comments

@jeusdi
Copy link

jeusdi commented Sep 7, 2022

Here my generated "QEntity" class:

public class QQdCF extends EntityPathBase<QdCF> {
 // ...
}

Here my repository:

@Repository
public interface QdCFRepository extends QuerydslR2dbcRepository<QdCF, Long> {
	
}

My service:

@RequiredArgsConstructor
@Service
public class QdCFService {

	private final PresenterMapper presenterMapper;
	private final QueryMapper queryMapper;
	private final QdCFRepository qdcfRepository;
	
	public Mono<PageableResponseModel<QdCFPresenter>> getQdCFSearchQueryDsl(
		QdCFSearchFormModel form,
		Pageable pageable
	) {
		Function<List<QdCFPresenter>, PageableResponseModel<QdCFPresenter>> toResponse =
			(items) -> PageableResponseModel.<QdCFPresenter>builder().size(items.size()).page(form.getPage()).results(items).build();

		return this.qdcfRepository.findAll(this.queryMapper.toPredicate(form))
			.map(this.presenterMapper::toPresenter)
			.collectList()
			.map(toResponse);
	}

Everything is straighforward.

Nevertheless, I'm getting this error message on startup:

Caused by: java.lang.ClassCastException: class cat.gencat.clt.git.backend.model.persistency.QQdCF cannot be cast to class com.querydsl.sql.RelationalPathBase (cat.gencat.clt.git.backend.model.persistency.QQdCF and com.querydsl.sql.RelationalPathBase are in unnamed module of loader 'app')

	at com.infobip.spring.data.common.QuerydslExpressionFactory.getRelationalPathBaseFromQueryClass(QuerydslExpressionFactory.java:177) ~[infobip-spring-data-common-7.2.0.jar:na]

	at com.infobip.spring.data.common.QuerydslExpressionFactory.getRelationalPathBaseFromQueryRepositoryClass(QuerydslExpressionFactory.java:157) ~[infobip-spring-data-common-7.2.0.jar:na]

	at com.infobip.spring.data.r2dbc.QuerydslR2dbcRepositoryFactory.getRepositoryFragments(QuerydslR2dbcRepositoryFactory.java:67) ~[infobip-spring-data-r2dbc-querydsl-7.2.0.jar:na]

	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryComposition(RepositoryFactorySupport.java:436) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:301) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:323) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.util.Lazy.getNullable(Lazy.java:231) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.util.Lazy.get(Lazy.java:115) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:329) ~[spring-data-commons-2.7.2.jar:2.7.2]

	at org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactoryBean.afterPropertiesSet(R2dbcRepositoryFactoryBean.java:179) ~[spring-data-r2dbc-1.5.2.jar:1.5.2]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.22.jar:5.3.22]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.22.jar:5.3.22]

	... 44 common frames omitted

Any ideas?

@lpandzic
Copy link
Member

lpandzic commented Sep 8, 2022

How are you generating Q classes?
You should be using https://github.com/infobip/infobip-spring-data-querydsl#AnnotationProcessor.

extends EntityPathBase

and

QuerydslR2dbcRepository

provide a hint that you're using JPA Q class generator and need R2dbc featureset.

@lpandzic
Copy link
Member

I'm gonna close this one as stale, feel free to reopen if it still applies.

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

No branches or pull requests

2 participants