Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Problem with Query: MEMBER OF with more than one Object?

JPA 1.0 JPQL does not allow collection arguments, nor does EclipseLink in its
current JPQL support.  EclipseLink does support this through is Expression
criteria API.

ExpressionBuilder v = new ExpressionBuilder();
Expression criteria = v.anyOf("components").get("id").in(listOfIds);
Query q = ((JpaEntityManager)em.getDelegate()).createQuery(criteria,
VendingMachine.class);

Another solution using JPQL would be to dynamically generate the JPQL and
generate a parameter for each element of the collection.  Or execute
multiple queries.

There is an enhancement request to have collection arguments supported by
JPQL, feel free to vote for the bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219814



t3_chris wrote:
> 
> Hi!
> 
> I'm trying to get a Query like this working:
> 
> List cmpList = <an Array List of the components>
> 
> Query q  = em.createQuery("SELECT v FROM Vendingmachine v WHERE
> :components MEMBER OF v.components");
> q.setParameter("components", cmpList);
> 
> (v.components is a Many-To-One List of VendingmachineComponents)
> 
> 
> This doesn't work at all. What i need to do, is to search for all
> Vendingmachines which contain any of the Components listed in the
> ArrayList cmpList.
> 
> I know i could first build my cmpList and then do the above query for
> every Component to get every corresponding vendingmachine but this seems a
> little bit cumbersome (would generate a hughe amount of sql-queries) to
> me.
> 
> What is the most elegant way to achieve my goal?
> 
> Thanks in advance for your help!
> 
> Best regards,
> christian reiter
> 
> 


-----
---
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/Problem-with-Query%3A-MEMBER-OF-with-more-than-one-Object--tp22078655p22079105.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top