Alex M
Alex M

Reputation: 511

JPQL querying a collection of non-entites

I want to make a JPQL query with a collection of non entities. This is my Table entity :

@Entity
@Table(name = "ct_table")
public class Table {
...

@CollectionOfElements(fetch = FetchType.EAGER)
@JoinTable(name = "ct_table_result", joinColumns = @JoinColumn(name = "tableId"))
@MapKey(columns = { @Column(name = "label") })
@Column(name = "value")
private Map<String, String> tableResults;
...

then I try to make a query like this

select count(*) from table where table.tableResults['somekey'].value='somevalue'

but I get the following exception:

Cannot create element join for a collection of non-entities!

Any suggestion??

thanks for your time

EDIT:

I use JPA 1 and hibernate 3.3. Default libraries in JBoss 5

Upvotes: 3

Views: 1937

Answers (1)

JB Nizet
JB Nizet

Reputation: 692181

The JPA 2 spec (page 139) defines the KEY() and VALUE() functions to access the key and the value of a map-valued element collection:

select count(t.id) from Table t 
where KEY(t.tableResults) = 'somekey' and VALUE(t.tableResults) = 'somevalue'

Upvotes: 8

Related Questions