iron24
iron24

Reputation: 141

How to use ReactiveQuerydslPredicateExecutor with spring webflux

I'm trying to use ReactiveQuerydslPredicateExecutor with spring webflux, using Mysql database and r2dbc. Repository extending ReactiveSortingRepository works perfectly.

However if I extend ReactiveQuerydslPredicateExecutor as well, then it won't compile. I'm enabling the r2dbc with EnableR2dbcRepositories. Back in the day before the reactive packages, one had to change the base package of "EnableJPARepositories" to the related "Q" one. However I can't find anything here, and it says there is no "findAll method".

The code:

@Table("user")
@AllArgsConstructor
@NoArgsConstructor
@Data
@QueryEntity
public class User {

    @Id
    Long id;

    String name;

    String email;
}
@Repository
public interface UserRepository extends ReactiveSortingRepository<User, Long>, ReactiveQuerydslPredicateExecutor<User> {
}

@Configuration
@EnableR2dbcRepositories(repositoryBaseClass = ReactiveCrudRepository.class)
public class AppConfig {
}

The error:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type User!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_211]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:82) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:251) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_211]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_211]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_211]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:252) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:381) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_211]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_211]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_211]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:382) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:94) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.r2dbc.repository.query.PartTreeR2dbcQuery.<init>(PartTreeR2dbcQuery.java:66) ~[spring-data-r2dbc-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    ... 55 common frames omitted

*** EDIT: ***

my database connection (in application.properties):

spring.r2dbc.url=r2dbc:mysql://127.0.0.1:3306/testdb
spring.r2dbc.username=root
spring.r2dbc.password=

my pom.xml: (I'm using the newest version of everything, exclusions are there, because version conflicts of the same package. Older ones are excluded.)

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <version>2.3.7.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-r2dbc</artifactId>
            <version>2.3.7.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.github.jasync-sql</groupId>
            <artifactId>jasync-r2dbc-mysql</artifactId>
            <version>1.1.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlin-stdlib</artifactId>
                    <groupId>org.jetbrains.kotlin</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlin-stdlib-common</artifactId>
                    <groupId>org.jetbrains.kotlin</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty-handler</artifactId>
                    <groupId>io.netty</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty-transport</artifactId>
                    <groupId>io.netty</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-sql-spring</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

Upvotes: 1

Views: 2506

Answers (1)

Jerry Pan
Jerry Pan

Reputation: 21

There is no repository such as SimpleR2dbcRepository implements ReactiveQuerydslPredicateExecutor.

In JPA, there is QuerydslJpaPredicateExecutor implements QuerydslPredicateExecutor.

So if your repository implements QuerydslPredicateExecutor, Spring Data JPA can create a proxy to use methods of SimpleJpaRepository and QuerydslJpaPredicateExecutor for your repository.

Querydsl has not supported r2dbc yet.

Upvotes: 2

Related Questions