user6522169
user6522169

Reputation: 71

Spring Data findAllById not work properly

I use spring-data-jpa-2.0.9.RELEASE lib. When I'd like to use JpaRepository.findAllById(Iterable ids) with 2 ids debug show me error

org.eclipse.persistence.exceptions.DatabaseException: 
Internal Exception: java.sql.SQLException: Operand should contain 1 column(s)
Error Code: 1241
Call: SELECT ID, CONFIGURATION, IMPORT_ID, NAME, STATE FROM TB_MARKET WHERE (ID IN ((?,?)))
Query: ReadAllQuery(referenceClass=MarketEntity sql="SELECT ID, CONFIGURATION, IMPORT_ID, NAME, STATE FROM TB_MARKET WHERE (ID IN (?))")

Error code 1241 for MySQL say that to much ( )

Upvotes: 3

Views: 4278

Answers (1)

locus2k
locus2k

Reputation: 2935

First Id try updating to the latest Spring data jpa library which is 2.1.1.RELEASE

for Maven:

<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>2.1.1.RELEASE</version>
</dependency>

If you are unable to update the libraries it might be better to roll your own query in your repository if this is a known issue in the version you're using:

In your repository in question add:

List<Entity> findByIdIn(Set<Integer> ids);

Having the id's as a set will prevent duplicate id's from being in the final query when it gets translated to the sql statement.

Upvotes: 2

Related Questions