You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by e33238 <e3...@hotmail.com> on 2007/06/26 00:31:35 UTC

Using MethodQL

I'm trying to figure out how to use MethodQL. This is the example given in
the UserGuide:

// the method query language is 'openjpa.MethodQL'.
// set the query string to the method to execute, including full class name;
if
// the class is in the candidate class' package or in the query imports, you
// can omit the package; if the method is in the candidate class, you can
omit
// the class name and just specify the method name
OpenJPAEntityManager oem = OpenJPAPersistence.cast(emf);
OpenJPAQuery q = oem.createQuery("openjpa.MethodQL",
"com.xyz.Finder.getByName");

// set the type of objects that the method returns
q.setResultClass(Person.class);

// parameters are passed the same way as in standard queries
q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");

// this executes your method to get the results
List results = q.getResultList();


I created a Person class (that has "firstName" and "lastName") and a Finder
class that has a static getByName() method. But I got an error when
q.getResultList() is called:--

<0.9.7-incubating nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: The parameter name or
position "firstName" passed to execute() is not valid.  All map keys must be
a declared parameter name or a number matching the parameter position. 

Any suggestions on what I may be doing wrong?

BTW, the UserGuide does not give examples or go into details on a lot of the
features. Any other documentation available besides the UserGuide and
Javadoc?

Thanks!
-- 
View this message in context: http://www.nabble.com/Using-MethodQL-tf3979366.html#a11296891
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Using MethodQL

Posted by Patrick Linskey <pl...@gmail.com>.
> Now getByName() will be called correctly, with "firstName" and "lastName" in
> the "params" map. I'm sure this is not the correct way, but I couldn't
> figure out how else I can call declareParameters(). Without calling
> declareParameters(), I'll get the ArgumentException.

Sounds like a bug -- OpenJPA should be able to infer the parameters
from the signature when there is no method overloading, and in the
case where there is method overloading, it'd be nice if OpenJPA would
allow the args specification to happen inline in the method
declaration.

-Patrick

On 6/26/07, e33238 <e3...@hotmail.com> wrote:
>
> I'm tracing through the code to find out what the problem was, and it seems
> that it'll work if I do this:
>
> OpenJPAQuery q =
> oem.createQuery("openjpa.MethodQL","com.xyz.Finder.getByName");
> q.setResultClass(Person.class);
> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
> ((QueryImpl)q).getDelegate().declareParameters("String firstName, String
> lastName"); //<== additional line
> List results = q.getResultList();
>
> Now getByName() will be called correctly, with "firstName" and "lastName" in
> the "params" map. I'm sure this is not the correct way, but I couldn't
> figure out how else I can call declareParameters(). Without calling
> declareParameters(), I'll get the ArgumentException.
>
> Also, I'm trying to find out how to use the RemoteCommitProvider. Basically
> everytime a commit happens, I'd like to send some notification to a remote
> server to track the changes. Sounds like RemoteCommitProvider is exactly
> what I wanted, so any examples of how to implement my own
> RemoteCommitProvier and how it's used would really help. Thanks!! =)
>
>
> Marc Prud'hommeaux wrote:
> >
> >
> > MethodQL is not a widely-used feature, so I wouldn't be surprised if
> > there might be a bug in there somewhere.
> >
> > What does your getByName() method look like? Also, if you just
> > exclude the parameter declaration from the code, do you still get the
> > same exception?
> >
> >> BTW, the UserGuide does not give examples or go into details on a
> >> lot of the
> >> features. Any other documentation available besides the UserGuide and
> >> Javadoc?
> >
> > The user guide and javadoc are the 2 main sources of documentation.
> > There are occasional examples on the wiki at openjpa.apache.org, but
> > there aren't that many at this time.
> >
> > Are there other features that you find under-documented? We are
> > always looking to improve the docs.
> >
> >
> >
> > On Jun 25, 2007, at 3:31 PM, e33238 wrote:
> >
> >>
> >> I'm trying to figure out how to use MethodQL. This is the example
> >> given in
> >> the UserGuide:
> >>
> >> // the method query language is 'openjpa.MethodQL'.
> >> // set the query string to the method to execute, including full
> >> class name;
> >> if
> >> // the class is in the candidate class' package or in the query
> >> imports, you
> >> // can omit the package; if the method is in the candidate class,
> >> you can
> >> omit
> >> // the class name and just specify the method name
> >> OpenJPAEntityManager oem = OpenJPAPersistence.cast(emf);
> >> OpenJPAQuery q = oem.createQuery("openjpa.MethodQL",
> >> "com.xyz.Finder.getByName");
> >>
> >> // set the type of objects that the method returns
> >> q.setResultClass(Person.class);
> >>
> >> // parameters are passed the same way as in standard queries
> >> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
> >>
> >> // this executes your method to get the results
> >> List results = q.getResultList();
> >>
> >>
> >> I created a Person class (that has "firstName" and "lastName") and
> >> a Finder
> >> class that has a static getByName() method. But I got an error when
> >> q.getResultList() is called:--
> >>
> >> <0.9.7-incubating nonfatal user error>
> >> org.apache.openjpa.persistence.ArgumentException: The parameter
> >> name or
> >> position "firstName" passed to execute() is not valid.  All map
> >> keys must be
> >> a declared parameter name or a number matching the parameter position.
> >>
> >> Any suggestions on what I may be doing wrong?
> >>
> >> BTW, the UserGuide does not give examples or go into details on a
> >> lot of the
> >> features. Any other documentation available besides the UserGuide and
> >> Javadoc?
> >>
> >> Thanks!
> >> --
> >> View this message in context: http://www.nabble.com/Using-MethodQL-
> >> tf3979366.html#a11296891
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Using-MethodQL-tf3979366.html#a11312798
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Re: Using MethodQL

Posted by e33238 <e3...@hotmail.com>.
I'm tracing through the code to find out what the problem was, and it seems
that it'll work if I do this:

OpenJPAQuery q =
oem.createQuery("openjpa.MethodQL","com.xyz.Finder.getByName");
q.setResultClass(Person.class);
q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
((QueryImpl)q).getDelegate().declareParameters("String firstName, String
lastName"); //<== additional line
List results = q.getResultList();

Now getByName() will be called correctly, with "firstName" and "lastName" in
the "params" map. I'm sure this is not the correct way, but I couldn't
figure out how else I can call declareParameters(). Without calling
declareParameters(), I'll get the ArgumentException.

Also, I'm trying to find out how to use the RemoteCommitProvider. Basically
everytime a commit happens, I'd like to send some notification to a remote
server to track the changes. Sounds like RemoteCommitProvider is exactly
what I wanted, so any examples of how to implement my own
RemoteCommitProvier and how it's used would really help. Thanks!! =)


Marc Prud'hommeaux wrote:
> 
> 
> MethodQL is not a widely-used feature, so I wouldn't be surprised if  
> there might be a bug in there somewhere.
> 
> What does your getByName() method look like? Also, if you just  
> exclude the parameter declaration from the code, do you still get the  
> same exception?
> 
>> BTW, the UserGuide does not give examples or go into details on a  
>> lot of the
>> features. Any other documentation available besides the UserGuide and
>> Javadoc?
> 
> The user guide and javadoc are the 2 main sources of documentation.  
> There are occasional examples on the wiki at openjpa.apache.org, but  
> there aren't that many at this time.
> 
> Are there other features that you find under-documented? We are  
> always looking to improve the docs.
> 
> 
> 
> On Jun 25, 2007, at 3:31 PM, e33238 wrote:
> 
>>
>> I'm trying to figure out how to use MethodQL. This is the example  
>> given in
>> the UserGuide:
>>
>> // the method query language is 'openjpa.MethodQL'.
>> // set the query string to the method to execute, including full  
>> class name;
>> if
>> // the class is in the candidate class' package or in the query  
>> imports, you
>> // can omit the package; if the method is in the candidate class,  
>> you can
>> omit
>> // the class name and just specify the method name
>> OpenJPAEntityManager oem = OpenJPAPersistence.cast(emf);
>> OpenJPAQuery q = oem.createQuery("openjpa.MethodQL",
>> "com.xyz.Finder.getByName");
>>
>> // set the type of objects that the method returns
>> q.setResultClass(Person.class);
>>
>> // parameters are passed the same way as in standard queries
>> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
>>
>> // this executes your method to get the results
>> List results = q.getResultList();
>>
>>
>> I created a Person class (that has "firstName" and "lastName") and  
>> a Finder
>> class that has a static getByName() method. But I got an error when
>> q.getResultList() is called:--
>>
>> <0.9.7-incubating nonfatal user error>
>> org.apache.openjpa.persistence.ArgumentException: The parameter  
>> name or
>> position "firstName" passed to execute() is not valid.  All map  
>> keys must be
>> a declared parameter name or a number matching the parameter position.
>>
>> Any suggestions on what I may be doing wrong?
>>
>> BTW, the UserGuide does not give examples or go into details on a  
>> lot of the
>> features. Any other documentation available besides the UserGuide and
>> Javadoc?
>>
>> Thanks!
>> -- 
>> View this message in context: http://www.nabble.com/Using-MethodQL- 
>> tf3979366.html#a11296891
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-MethodQL-tf3979366.html#a11312798
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Using MethodQL

Posted by Marc Prud'hommeaux <mp...@apache.org>.
MethodQL is not a widely-used feature, so I wouldn't be surprised if  
there might be a bug in there somewhere.

What does your getByName() method look like? Also, if you just  
exclude the parameter declaration from the code, do you still get the  
same exception?

> BTW, the UserGuide does not give examples or go into details on a  
> lot of the
> features. Any other documentation available besides the UserGuide and
> Javadoc?

The user guide and javadoc are the 2 main sources of documentation.  
There are occasional examples on the wiki at openjpa.apache.org, but  
there aren't that many at this time.

Are there other features that you find under-documented? We are  
always looking to improve the docs.



On Jun 25, 2007, at 3:31 PM, e33238 wrote:

>
> I'm trying to figure out how to use MethodQL. This is the example  
> given in
> the UserGuide:
>
> // the method query language is 'openjpa.MethodQL'.
> // set the query string to the method to execute, including full  
> class name;
> if
> // the class is in the candidate class' package or in the query  
> imports, you
> // can omit the package; if the method is in the candidate class,  
> you can
> omit
> // the class name and just specify the method name
> OpenJPAEntityManager oem = OpenJPAPersistence.cast(emf);
> OpenJPAQuery q = oem.createQuery("openjpa.MethodQL",
> "com.xyz.Finder.getByName");
>
> // set the type of objects that the method returns
> q.setResultClass(Person.class);
>
> // parameters are passed the same way as in standard queries
> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
>
> // this executes your method to get the results
> List results = q.getResultList();
>
>
> I created a Person class (that has "firstName" and "lastName") and  
> a Finder
> class that has a static getByName() method. But I got an error when
> q.getResultList() is called:--
>
> <0.9.7-incubating nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: The parameter  
> name or
> position "firstName" passed to execute() is not valid.  All map  
> keys must be
> a declared parameter name or a number matching the parameter position.
>
> Any suggestions on what I may be doing wrong?
>
> BTW, the UserGuide does not give examples or go into details on a  
> lot of the
> features. Any other documentation available besides the UserGuide and
> Javadoc?
>
> Thanks!
> -- 
> View this message in context: http://www.nabble.com/Using-MethodQL- 
> tf3979366.html#a11296891
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>