Skip to content

MSSQL: Using IsTrue or True in Query Method doesn't work on BIT columns #698

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

Closed
jsmwoolf opened this issue Dec 26, 2021 · 2 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@jsmwoolf
Copy link

Provided the following schema and Java code:

Schema

CREATE TABLE Books
(
  ID INTEGER,
  available BIT DEFAULT 1,
  Title NVARCHAR(128) NOT NULL,
  PRIMARY KEY (ID)
)

Book DTO

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(value = "Books")
public class Book {
    @Id
    private Integer id;
    private String name;
    private Boolean available;
}

Book Repository

public interface BookRepository extends R2dbcRepository<Book, Integer > {
    Mono<Boolean> existsByIdAndAvailableTrue(Integer id);
}

Any attempts to call existsByIdAndAvailableTrue() throws the following error:
io.r2dbc.mssql.ExceptionFactory$MssqlBadGrammarException: Invalid column name 'TRUE'.

The query that the function generates is as follows:
SELECT Books.id, Books.name, Books.available FROM Books WHERE Books.id = @P0_id AND (Books.available = TRUE)

The expected behavior should be that, given a BIT column mapped to a Java Boolean value, Spring Data R2DBC should be able to correctly check whether the BIT column is TRUE or FALSE.

@mp911de
Copy link
Member

mp911de commented Jan 17, 2022

See also spring-projects/spring-data-relational#908

This is a bug and we need to fix it. We fixed a similar bug already in Spring Data JDBC.

@mp911de mp911de pinned this issue Jan 17, 2022
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 17, 2022
@mp911de mp911de self-assigned this Jan 17, 2022
@mp911de mp911de added this to the 1.4.2 (2021.1.2) milestone Jan 17, 2022
mp911de added a commit that referenced this issue Jan 17, 2022
Reformat code. Add author tags.

See: #698
Original pull request: #708.
mp911de pushed a commit that referenced this issue Jan 17, 2022
mp911de added a commit that referenced this issue Jan 17, 2022
Reformat code. Add author tags.

See: #698
Original pull request: #708.
mp911de pushed a commit that referenced this issue Jan 17, 2022
mp911de added a commit that referenced this issue Jan 17, 2022
Reformat code. Add author tags.

See: #698
Original pull request: #708.
@mp911de mp911de unpinned this issue Jan 18, 2022
@aiai-guenz
Copy link

For PostgreSQL, it's still not working:
image
results in
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants