openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Howard Mak <h...@antennasoftware.com>
Subject Re: OpenJPA querying on element collections
Date Wed, 28 Sep 2011 12:12:36 GMT
KEY was exactly what I was looking for. Thanks!

- Howard

----- Reply message -----
From: "Rick Curtis" <curtisr7@gmail.com>
To: "users@openjpa.apache.org" <users@openjpa.apache.org>
Subject: OpenJPA querying on element collections
Date: Tue, Sep 27, 2011 8:35 am



Howard -

Yes, it is possible. I'd recommend reading through the JPA 2.0 spec[1] for a
more thorough answer.

Try something like this: SELECT x FROM Item x WHERE KEY(m_properties)= 'x' <
'h'

Thanks,
Rick

[1] JPA 2.0 -- 4.4.4 Path Expressions -- snippet
..
In the following query, photos is a map from photo label to filename.
SELECT i.name, VALUE(p) FROM Item i JOIN i.photos p WHERE KEY(p) LIKE
‘%egret’

In the above query the identification variable p designates an abstract
schema type corresponding to the
map value. The results of VALUE(p) and KEY(p) are the map value and the map
key associated with
p, respectively.

The following query is equivalent:
SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) LIKE ‘%egret’

....


On Mon, Sep 26, 2011 at 1:21 PM, Howard Mak <hmak@antennasoftware.com>wrote:

> Hi,
>
> Does anyone know if OpenJPA supports queries on element collections?
>
> Given:
>                @Entity
>                @Table(name="items")
>                public class Item implements Serializable {
>                                @Id
>                                @Column(name="seq_no")
>                                private long m_seqNo;
>
>                                @ElementCollection(fetch=FetchType.LAZY)
>                                @CollectionTable(name="properties",
> joinColumns={ @JoinColumn(name="seq_no") })
>                                @MapKeyColumn(name = "prop_name")
>                                @Column(name="prop_val")
>                                private Map<String, String> m_properties;
>                }
> ... basically, 1-to-many from "items" to "properties" with schema
>                Table: items
>                Column: seq_no               // primary key
>
>                Table: properties
>                Column: seq_no               // foreign key to "items"
>                Column: prop_name      // m_properties keys
>                Column: prop_val            // m_properties values
>
> Then: running JPA query
>                SELECT x FROM Item x WHERE x.m_properties.get('x') < 'h'
> results in a parse exception for me on OpenJPA v2.0.0.
> Thanks.
>
> - Howard
>
> This email and any files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> Please note that any views or opinions presented in this email are solely
> those of the author and do not necessarily represent those of the company.
> Finally, the recipient should check this email and any attachments for the
> presence of viruses. The company accepts no liability for any damage caused
> by any virus transmitted by this email. If you have received this email in
> error please delete it and notify the system administrator at
> administrator@antennasoftware.com
>



--
*Rick Curtis*

This email and any files transmitted with it are confidential and intended solely for the
use of the individual or entity to whom they are addressed. Please note that any views or
opinions presented in this email are solely those of the author and do not necessarily represent
those of the company. Finally, the recipient should check this email and any attachments for
the presence of viruses. The company accepts no liability for any damage caused by any virus
transmitted by this email. If you have received this email in error please delete it and notify
the system administrator at administrator@antennasoftware.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message