-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JPQL to SQL translation error
PostPosted: Fri Feb 11, 2011 2:33 pm 
Newbie

Joined: Fri Feb 11, 2011 2:12 pm
Posts: 2
Hi, I'm a new person here and not very familiar with neither Hibernate nor Java Persistence.

I have a very simple JPQL query with one parameter:
Code:
select e from AtomicEUP e
join e.generics g
where g.processStep = :processStep


AtomicEUP.generics is a many-to-many relationship with Generic.measurements on the opposite side. Generic.processStep is a one-to-one relationship to an entity of type ProcessStep.

For some reason the query results in the following SQL query:
Code:
select
        atomiceup0_.ID as ID8_,
        [etc...]
    from
        E_U_P atomiceup0_
    inner join
        GENERICS_MEASUREMENTS generics1_
            on atomiceup0_.ID=generics1_.MEASUREMENTS_ID_FK
    inner join
        GENERIC generic2_
            on generics1_.GENERICS_ID_FK=generic2_.ID
    where
        generic2_.ID=?


The 'join' clause seems to be correctly translated, but there is no trace of the 'where' clause. The query fails with a message "ERROR [JDBCExceptionReporter] No value specified for parameter 1".

Is there something wrong with my JPQL query statement?


Top
 Profile  
 
 Post subject: Re: JPQL to SQL translation error
PostPosted: Mon Feb 14, 2011 5:47 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

How do you call the execution of your query?
Given the error, it seems that you are not giving any value to the parameter :processStep ...


Top
 Profile  
 
 Post subject: Re: JPQL to SQL translation error
PostPosted: Wed Feb 16, 2011 6:02 am 
Newbie

Joined: Fri Feb 11, 2011 2:12 pm
Posts: 2
overmeulen wrote:
Hi,

How do you call the execution of your query?
Given the error, it seems that you are not giving any value to the parameter :processStep ...


The call was originally made like this:
Code:
Query query = createQuery(findAtomicEUPsByProcessStep);
query.setParameter("processStep", step);
return query.getResultList();


So the parameter value was set. I went around this problem by accessing the Generic object in code and using it directly in the WHERE clause and replacing the JOIN clause with a MEMBER OF expression in the WHERE clause. The query is now like this:
Code:
select e from AtomicEUP e
where :generic MEMBER OF e.generics


This produces an SQL query with a subquery in the WHERE statement, which might result in a worse performance than the JOIN statement.
Code:
    select
        atomiceup0_.ID as ID8_,
        [etc...]
    from
        E_U_P atomiceup0_
    where
        ? in (
            select
                generic2_.ID
            from
                GENERICS_MEASUREMENTS generics1_,
                GENERIC generic2_
            where
                atomiceup0_.ID=generics1_.MEASUREMENTS_ID_FK
                and generics1_.GENERICS_ID_FK=generic2_.ID
        )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.