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

Syntax error with SELECT queries #157

Open
eau-de-la-seine opened this issue Apr 11, 2020 · 0 comments
Open

Syntax error with SELECT queries #157

eau-de-la-seine opened this issue Apr 11, 2020 · 0 comments

Comments

@eau-de-la-seine
Copy link

Versions

  • Driver: io.r2dbc:r2dbc-h2:0.8.3.RELEASE
  • Database: H2
  • Java: openjdk version "11.0.6" 2020-01-14
  • OS: Ubuntu 18.04.4 LTS

Current Behavior

According to the Spring R2DBC documentation I can use this syntax (copy/paste from documentation):

@Query("select u from User u")
Stream<User> findAllByCustomQueryAndStream();

Error A

Here the equivalent with my code:

@Query("SELECT u FROM UserEntity u WHERE u.id = :email AND u.hash = :hash")
Mono<UserEntity> findByEmailAndHash(String email, String hash);

Error: Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USERENTITY" not found; SQL statement:
So the Entity's name isn't supported, I have to use table's name.

Error B

Same example but with table's name:

@Query("SELECT u FROM user u WHERE u.id = :email AND u.hash = :hash")
Mono<UserEntity> findByEmailAndHash(String email, String hash);

Error: Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "U" not found; SQL statement:
So it considers u as a column, because u.* works as expected

Error C

The FROM x syntax:

@Query("FROM user WHERE id = :email AND hash = :hash")
Mono<UserEntity> findByEmailAndHash(String email, String hash);

Error: Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "FROM[*] USER WHERE ID = $1 AND HASH = $2"; SQL statement:
This syntactic sugar where we are omitting SELECT * doesn't work (it doesn't really matter for me, just wanted to tell you)

The only solution which works

The only solution which works is SELECT * :

@Query("SELECT * FROM user WHERE id = :email AND hash = :hash")
Mono<UserEntity> findByEmailAndHash(String email, String hash);

Code

For my Entities I don't use JPA annotations/classes, I use these:

import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.mapping.Column;

My repository:

import fr.ekinci.project.repository.entity.UserEntity;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Mono;

public interface UserRepository extends ReactiveCrudRepository<UserEntity, String> {
    // See examples shown above
}

Questions

Question 1: Are error A, B and C are expected behaviours or will they be supported with 1.0.0 ?

It doesn't work without @Query:

Mono<UserEntity> findByIdAndHash(String email, String hash);

Error: Caused by: java.lang.UnsupportedOperationException: Query derivation not yet supported!
Question 2: Will "Derived Query Methods" be supported with 1.0.0 ?

Question 3: I have noticed that we are using the $ symbol for placeholders with R2DBC, instead of ? like in JPA, was there a specific reason?

Question 4: Does the org.springframework.transaction.annotation.Transactional annotation on my services' method work when we are using ReactiveCrudRepository or only when we are using org.springframework.data.r2dbc.core.DatabaseClient instance?

Thanks

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

1 participant