You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by sim085 <si...@hotmail.com> on 2015/08/16 20:06:39 UTC

TypedQuery on ElementCollection

Hello,

I have an object User which has a Map<String, String> variable named
"properties". This variable is declared as follows:

[code]
  @ElementCollection(fetch = FetchType.EAGER)
  @JoinTable(name="USER_PROPERTIES", 
      joinColumns=@JoinColumn(name="USER_ID"))
  @MapKeyColumn(name="Name")
  @Column(name="Value")
  private Map<String, String> properties = new HashMap<>();
[/code]

I would like to now load all Users which have some given properties (ex:
where user has property "HAIR" equals "BROWN" and "EYES" equals "WHITE").

With normal SQL the query would look something like this:

[code]
SELECT u.ID FROM USERS u, USER_PROPERTIES p1, USER_PROPERTIES p2
WHERE u.ID = p1.USER_ID AND u.ID = p2.USER_ID
AND (p1.NAME = 'HAIR' AND p1.VALUE = 'BROWS')
AND (p2.NAME = 'EYES' AND p2.VALUE = 'WHITE');
[/code]

However I do not know how to write this in JPQL

Is it possible to write the above SQL with JPQL?





--
View this message in context: http://openjpa.208410.n2.nabble.com/TypedQuery-on-ElementCollection-tp7588447.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.