Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 797229CA8 for ; Tue, 27 Sep 2011 12:35:27 +0000 (UTC) Received: (qmail 67840 invoked by uid 500); 27 Sep 2011 12:35:27 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 67739 invoked by uid 500); 27 Sep 2011 12:35:26 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 67731 invoked by uid 99); 27 Sep 2011 12:35:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2011 12:35:26 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of curtisr7@gmail.com designates 209.85.215.174 as permitted sender) Received: from [209.85.215.174] (HELO mail-ey0-f174.google.com) (209.85.215.174) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2011 12:35:21 +0000 Received: by eya28 with SMTP id 28so6006327eya.33 for ; Tue, 27 Sep 2011 05:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=IlC+f2RjkybXQAItzVcJyNE9TvJQ2bwLigw2NZAFaKQ=; b=igtx+EL/quyQoD6dxjp6M8alFqSqgOQ4gwupFmr7NzOMwMeheyLGInSFKRbC9XH8if d3HYExApA61ZkY/FIyi8qakJPfSBPR9RQzq5gKylxh9BbmtnxswvGLz2EN4JS3d89m8u Td6ltWWFuvtERfzBIf4AkHfgyo7Qba796M/2g= MIME-Version: 1.0 Received: by 10.213.26.210 with SMTP id f18mr380961ebc.110.1317126900383; Tue, 27 Sep 2011 05:35:00 -0700 (PDT) Received: by 10.213.114.10 with HTTP; Tue, 27 Sep 2011 05:34:59 -0700 (PDT) In-Reply-To: <54FF0AD851D9354C8F397819F5FC99AD0EA075@BOSMAIL01.antennasoftware.com> References: <54FF0AD851D9354C8F397819F5FC99AD0EA075@BOSMAIL01.antennasoftware.com> Date: Tue, 27 Sep 2011 07:34:59 -0500 Message-ID: Subject: Re: OpenJPA querying on element collections From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=0015174c34ae057f4704adeb8156 --0015174c34ae057f4704adeb8156 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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)=3D '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 =91%egret=92 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 =91%egret=92 .... On Mon, Sep 26, 2011 at 1:21 PM, Howard Mak wrote= : > Hi, > > Does anyone know if OpenJPA supports queries on element collections? > > Given: > @Entity > @Table(name=3D"items") > public class Item implements Serializable { > @Id > @Column(name=3D"seq_no") > private long m_seqNo; > > @ElementCollection(fetch=3DFetchType.LAZY) > @CollectionTable(name=3D"properties", > joinColumns=3D{ @JoinColumn(name=3D"seq_no") }) > @MapKeyColumn(name =3D "prop_name") > @Column(name=3D"prop_val") > private Map 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 intende= d > 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 th= e > presence of viruses. The company accepts no liability for any damage caus= ed > by any virus transmitted by this email. If you have received this email i= n > error please delete it and notify the system administrator at > administrator@antennasoftware.com > --=20 *Rick Curtis* --0015174c34ae057f4704adeb8156--