I would like to generate a query with my R2dbcRepository
. In Spring Data JPA
the documentation says to use #{#entityName}
to get an Entity
if a repository is generic, however I can't find the equivalent in R2DBC
.
I'm using a H2 in memory database: r2dbc:h2:mem:///~/db/testdb
R2dbcRepository
public interface UUIDRepository<Model, IdType> extends R2dbcRepository<Model, IdType> {
Mono<Model> findByIdAndUserUUID(Long id, UUID uuid);
@Query("SELECT * FROM #{#entityName} WHERE model.id = :id AND (model.user_uuid = :uuid OR model.user_uuid IS NULL)")
Mono<Model> findByIdAndUserUUIDOrUserUUIDIsNull(@Param("id") Long id, @Param("uuid") UUID uuid);
}
Exception
Caused by: io.r2dbc.spi.R2dbcBadGrammarException: [42000] [42000] Syntax error in SQL statement "FROM [*]#{#entityName} model WHERE model.id = $1 AND (model.user_uuid = $2 OR model.user_uuid IS NULL)"; SQL statement:
I know the syntax for the rest of the query is correct as if I replace #{#entityName}
with a table name it works fine.
How can I insert the entity name in a query when using R2DBC
?