You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importorg.springframework.data.jpa.repository.JpaRepository;
importorg.springframework.data.jpa.repository.Query;
importorg.springframework.stereotype.Repository;
importjava.util.Map;
@RepositoryinterfaceMyEntityJpaRepoextendsJpaRepository<MyEntity, String> {
@Query("SELECT t.id as id, t.foo as foo, t.bar as bar FROM MyEntity t WHERE t.id = ?1")
MapfindSomething(Stringid);
}
And table data:
id
foo
bar
"1"
"x"
null
The Map instance returned does not behave correctly.
// PseudocodeMapmap = myEntityJpaRepo.findSomething("1");
// the following are truemap == { "id": "1", "foo": "x", "bar": null }
map.keySet() == { "id", "foo", "bar" }
map.get("id").equals("1") // truemap.get("foo").equals("x") // truemap.get("bar") == null// truemap.containsKey("id") == truemap.keySet().contains("id") == truemap.containsKey("foo") == truemap.keySet().contains("foo") == true// the following should be true, but are falsemap.containsKey("bar") == truemap.keySet().contains("bar") == true
It looks like containsKey method is not implemented correctly on AbstractJpaQuery
I am not sure we can actually completely fix this due to Hibernate's refined alias handling being aligned with SQL which assumes all caps aliases by default. Depending on the database you're using you can explicitly quote the aliases in the query which should make them appear in exactly the case you defined it.
Jens Schauder – Would you mind having a look at this? Maybe we can tweak the implementation slightly?
John Mann opened DATAJPA-1301 and commented
Given the JpARepository:
And table data:
The Map instance returned does not behave correctly.
It looks like
containsKey
method is not implemented correctly on AbstractJpaQueryAffects: 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)
The text was updated successfully, but these errors were encountered: