Skip to content

Map instances returned by JpaRepository queries do not handle null map values correctly [DATAJPA-1301] #1625

Closed
@spring-projects-issues

Description

@spring-projects-issues

John Mann opened DATAJPA-1301 and commented

Given the JpARepository:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
interface MyEntityJpaRepo extends JpaRepository<MyEntity, String> {

    @Query("SELECT t.id as id, t.foo as foo, t.bar as bar FROM MyEntity t WHERE t.id = ?1")
    Map findSomething(String id);

}

And table data:

id foo bar
"1" "x" null

The Map instance returned does not behave correctly.

// Pseudocode
Map map = myEntityJpaRepo.findSomething("1");

// the following are true
map == { "id": "1", "foo": "x", "bar": null }
map.keySet() == { "id", "foo", "bar" }


map.get("id").equals("1")   // true
map.get("foo").equals("x")  // true
map.get("bar") == null      // true

map.containsKey("id") == true
map.keySet().contains("id") == true
map.containsKey("foo") == true
map.keySet().contains("foo") == true

// the following should be true, but are false
map.containsKey("bar") == true
map.keySet().contains("bar") == true

It looks like containsKey method is not implemented correctly on AbstractJpaQuery


Affects: 2.1 M1 (Lovelace), 1.11.10 (Ingalls SR10), 2.0.5 (Kay SR5)

Referenced from: pull request #262

Backported to: 2.0.6 (Kay SR6), 1.11.11 (Ingalls SR11)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions