You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by C N Davies <cn...@cndavies.com> on 2010/02/26 14:28:03 UTC

Query Mayhem

Hi,

 

I am using Open JPA 2.0 Beta and I have some JPQL that seems to be confusing
the parser. Here is my query:

 

SELECT ct.assets.queue.uniqueid from Contract ct where ct.uniqueid =
'0000012444686ECC'

 

Here is my parse error:

 

 

"Error message: No field named "queue" in class "class
com.trm.core.Contract".

 

 

If you look at my query there is no reference to "queue" in the Contract
class,  the dotted notation shows I am looking for the queue in the Contract
entity's "Assets" vector

 

Here is the Contract entity snippet:

 

public class Contract extends MasterObject {

 

..snip..

 

            /** The assets. */

            @OneToMany(cascade={CascadeType.ALL})

            private List<Asset> assets;

 

..snip..

 

}

 

 

 

Here is the Asset entity:

 

public class Asset extends CoreObject {

            

..snip..

 

/** The queue. */

            @ManyToOne(cascade={CascadeType.REFRESH})

            private Queue queue;

..snip..

                

}

 

 

So I believe my JPQL is correct and that OpenJPA is confused. Or maybe I am
J 

 

Thanks for any pointers!

 

Chris

 


Re: Query Mayhem

Posted by catalina wei <ca...@gmail.com>.
Chris,
In JPQL, the path navigation can not be made on Mult/collectioni-valued
field.

A alternative JPQL to try:
SELECT a.queue.uniqueid from Contract ct JOIN ct.assets a where ct.uniqueid
= '0000012444686ECC'

Snice 'queue' is a single-valued-object-path (ManyToOne) which you can
navigate thru to its state-field 'uniqueid'.

equivalent JPQL:
SELECT a.queue.uniqueid from Contract ct, IN(ct.assets) a where ct.uniqueid
= '0000012444686ECC'

Essentially, a range variable (e.g. identification_variable) should be
defined over collection-valued-path (i.e. ToMany association field), then
use that range variable to do further navigation.

Catalina

On Fri, Feb 26, 2010 at 5:28 AM, C N Davies <cn...@cndavies.com> wrote:

> Hi,
>
>
>
> I am using Open JPA 2.0 Beta and I have some JPQL that seems to be
> confusing
> the parser. Here is my query:
>
>
>
> SELECT ct.assets.queue.uniqueid from Contract ct where ct.uniqueid =
> '0000012444686ECC'
>
>
>
> Here is my parse error:
>
>
>
>
>
> "Error message: No field named "queue" in class "class
> com.trm.core.Contract".
>
>
>
>
>
> If you look at my query there is no reference to "queue" in the Contract
> class,  the dotted notation shows I am looking for the queue in the
> Contract
> entity's "Assets" vector
>
>
>
> Here is the Contract entity snippet:
>
>
>
> public class Contract extends MasterObject {
>
>
>
> ..snip..
>
>
>
>            /** The assets. */
>
>            @OneToMany(cascade={CascadeType.ALL})
>
>            private List<Asset> assets;
>
>
>
> ..snip..
>
>
>
> }
>
>
>
>
>
>
>
> Here is the Asset entity:
>
>
>
> public class Asset extends CoreObject {
>
>
>
> ..snip..
>
>
>
> /** The queue. */
>
>            @ManyToOne(cascade={CascadeType.REFRESH})
>
>            private Queue queue;
>
> ..snip..
>
>
>
> }
>
>
>
>
>
> So I believe my JPQL is correct and that OpenJPA is confused. Or maybe I am
> J
>
>
>
> Thanks for any pointers!
>
>
>
> Chris
>
>
>
>