Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] how can I reference a foreign key in ejbql where condition?

Are you using JPA?  EJBQL/JPQL is normally used from JPA using the JPA Query
interface.

For using EJBQL/JPQL with an EclipseLink ReadAllQuery you need to set the
argument names and values.

i.e.
query.setEJBQLString("Select OBJECT(sg) from sg sg where sg.foreignField =
?1");
query.addArgument("1");
query.addArgumentValue(id);

Also ensure you JPQL is valid, and you have an attribute "foreignField" in
your class.  You could also use an EclipseLink Expression query, where you
can use getField() to reference a database column directly.



zamek42 wrote:
> 
> Hi All,
> 
> I would like to filter a table by foreign key in ejbql:
> 
> ForeignField fg = new ForeingField(id);
> ArrayList args= new ArrayList();
> args.add(fg);
> ...
> query.setEJBQLString("Select OBJECT(sg) from sg sg where sg.foreignField =
> ?1");
> query.addArgumentValues(args);
> 
> I get an error:
> Exception Description: The parameter name [1] in the query's selection
> criteria does not match any parameter name defined in the query.
> 
> I tried it with id as Integer, but it doesn't works.
> 
> thx a lot,
> Zamek
> 
> 


-----
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://old.nabble.com/how-can-I-reference-a-foreign-key-in-ejbql-where-condition--tp26263446p26284677.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top