Skip to content

Simple Type projections: Couldn't find PersistentEntity #83

@zolash

Description

@zolash

I saw a similar post on simple type projections for repositories, but I'm not using repositories.

@Bean
ConnectionFactory connectionFactory() {
    PostgresqlConnectionConfiguration config = PostgresqlConnectionConfiguration.builder()
            .host(host)
            .port(5432)
            .database(databaseName)
            .username(username)
            .password(password)
            .build();
    return new PostgresqlConnectionFactory(config);
}

public DatabaseClient getClient() {
    return DatabaseClient.create(connectionFactory());
}

public Mono<String> getAttemptCount() {
        return postgresDatabaseConfig.getClient()
                .execute()
                .sql("SELECT recipient FROM entity WHERE uuid = CAST($1 AS UUID)")
                .bind("$1", "5e89de44-a4c4-40eb-4321-25f4b91654cf")
                .as(String.class)
                .fetch()
                .first();
}

I get `"error": "Internal Server Error",
    "message": "Couldn't find PersistentEntity for type class java.lang.String!"`

I have been able to get similar code working with 
<dependency>
    <groupId>io.r2dbc</groupId>
    <artifactId>r2dbc-client</artifactId>
    <version>1.0.0.M7</version>
  </dependency>

public Mono<String> getAttemptCount() {
        return postgresConfig.getR2DBCClient()
                .withHandle(handle -> 
                    handle.select("SELECT recipient FROM entity WHERE uuid = CAST($1 AS UUID)")
                     .bind("$1", "5e89de44-a4c4-40eb-4321-25f4b91654cf")
                    .mapResult(result -> result.map((row, rowData) -> row.get("recipient", Integer.class))))
                    .next();
    }

but I don't see any reason why I can't use spring-data-r2dbc itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions