0

Here is a part of my Person class:

@Entity
public class Person {
    @ElementCollection(fetch = FetchType.EAGER)
    private Map<String, String> externalPropertyMap = new HashMap<>();
}

So i need to select every Person with exact key and value from this map. For example select every Person with key="prefferedNumber" and value="123456"

How can i do this?

juergen d
  • 201,996
  • 37
  • 293
  • 362
leon0399
  • 79
  • 8

1 Answers1

1

Actually this is not accurated:

So i need to select every Person with exact key and value from this map

You have a HashMap, a Map implementation which don't allow repeated keys, so, you just will get one single value for each key from the HashMap.

To achieve this you need to use another Map implementation, but don't worry, someone has your problem already:

  • Try this implementation
  • MultiMap from ApacheCommons

    A MultiMap is a Map with slightly different semantics. Putting a value into the Map will add the value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key.

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • But every Person is individual class, so every map is individual too and keys will not repeat at each person – leon0399 Jun 03 '16 at 11:38