[
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?
|
Why are you using a ReadAllQuery, if you are using JPA and JPQL? Just create
a JPA Query,
Query query = em.createQuery("Select Object(entity) from ChairImpl entity
where entity.institute=:institute");
query.setParameter("institute", new Integer(10));
List result = query.getResultList();
If you need to use a ReadAllQuery with EJBQL then you cannot use
addArgumentValue(), as it seems to have issues, you will need to execute it
as a parametrized query.
i.e.
ReadAllQuery query = new ReadAllQuery(ChairImpl.getClass());
query.setEJBQLString("Select Object(entity) from ChairImpl entity where
entity.institute=?1");
query.addArgument("1");
EntityManager em = this.getEntityManager();
Query query = JpaHelper.createQuery(query, em);
query.setParameter("1", new Integer(10));
List result = query.getResultList();
zamek42 wrote:
>
> hello James,
>
> thx for response.
>
> James Sutherland wrote:
>>
>> 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);
>>
>>
>
> I get filter criteria from smartgwt, which is a gwt frontend. I need ejbql
> because it sends filtering criterias in a Map<String,String>. I don't want
> to use an unecessary string parser, simply put criteria text into the sql.
> For a test I make a simple query:
>
> ReadAllQuery query = new ReadAllQuery(ChairImpl.getClass());
> query.setEJBQLString("Select Object(entity) from ChairImpl entity where
> entity.institute=?1");
> query.addArgument("1");
> query.addArgumentValue(new Integer(10));
> EntityManager em = this.getEntityManager();
> List result = JpaHelper.createQuery(query, em).getResultList();
>
> this throws an error:
> java.lang.IllegalStateException: Query argument 1 not found in the list of
> parameters provided during query execution.
>
> ChairImpl has an attribute named institute:
> @ManyToOne
> @JoinColumn(nullable=false)
> public InstituteImpl getInstitute() {
> return institute;
> }
>
> public void setInstitute(InstituteImpl institute) {
> this.institute = institute;
> }
>
> What do I mistake?
>
> Perhaps JpaHelper.createQuery is unecessary? How can I use readAllQuery
> from glassfish directly?
>
> thx
> 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--tp26263446p26391063.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.