Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] QueryByExamplePolicy not being used on a ReadAllQuery

The addSpecialOperation can use anything that is a method on the Expression
class.
If you need something beyond that, you can use an Expression instead of QBE
(or even in addition).  Expressions allow for custom operators and
functions.


nickgoodman wrote:
> 
> Actually, this was Eclipselink, we've just ported and I mistyped.  And I
> discovered the problem... Somebody had extended the ReadAllQuery and not
> renamed it (so only the package was different), and they weren't handling
> the policies correctly.
> 
> Incidentially, this brings up the original question that I was looking
> into: I'd like to use a custom operation instead of "like".  Is that
> possible without modifying EclipseLink?
> 
> thanks,
>   Nick
> 
> 
> 
> James Sutherland wrote:
>> 
>> The code looks correct.  What is the SQL generated?  Is you String value
>> null?
>> 
>> You might want to try the same on EclipseLink, to see if it still occurs
>> (note, this is the EclipseLink forum, not TopLink Essentials).
>> 
>> 
>> 
>> nickgoodman wrote:
>>> 
>>> 
>>> I've got some code that appears to correctly use a QueryByExamplePolicy;
>>> however, when I look at the SQL generated via TopLink Essentials (I'm
>>> using WebLogic 10.3), I see it using equals instead of like for the
>>> comparison of attributes in the example object (the result set is
>>> clearly the equals query and not the like query).  The following code is
>>> what's being executed:
>>> 
>>> 
>>> /* searchPImpl has one field set to a value like "test%", and I want it
>>> to pickup values such as "test1", "test", "test  23", et cetera */
>>> 
>>> QueryByExamplePolicy policy = new QueryByExamplePolicy();
>>> policy.addSpecialOperation(String.class, "like");
>>> policy.addSpecialOperation(Integer.class, "equal");
>>> 		
>>> ReadAllQuery raq = new ReadAllQuery();
>>> raq.setExampleObject(searchPImpl);
>>> raq.setReferenceClass(searchPImpl.getClass());
>>> raq.setQueryByExamplePolicy(policy);
>>> 
>>> 
>>> ClientSession cs = getClientSession();
>>> ArrayList arrayList = new ArrayList((Vector) cs.executeQuery(raq));
>>> 
>>> 
>> 
>> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/QueryByExamplePolicy-not-being-used-on-a-ReadAllQuery-tp25647908p25696918.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top