-->
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.  [ 7 posts ] 
Author Message
 Post subject: JPQL to SQL not translated correctly
PostPosted: Thu Jan 16, 2014 8:54 am 
Newbie

Joined: Thu Jan 16, 2014 8:46 am
Posts: 4
This complex JPQL query which when encoded to sql for Postgres, is improperly translated.


JPA:
Code:
@NamedQuery(
   name="Operation.mailListWithValidLicense",
   query="SELECT DISTINCT o "
      + "FROM Operation o " // Operations for
      + "INNER JOIN o.protocols p "
      + "INNER JOIN p.protocolSchedules ps "
      + "WHERE EXISTS ("
         + "SELECT 'found' "
         + "FROM License l " // a license
         + "WHERE l.surgery = o.surgery " // for the current surgery
         + "AND l.revoked = FALSE " // which is unrevoked
         + "AND CURRENT_DATE BETWEEN l.startDate AND l.expiryDate" // and current
      + ") "
      + "AND p.cancelled = FALSE " // protocols not cancelled
      + "AND ps.submitted = FALSE AND ps.expired = FALSE " // schedules not submitted and not expired
      + "AND CURRENT_TIMESTAMP <= ps.scheduleDate " // not after schedule date
      + "AND ( "
         + "( "
            + "ps.mailed IS NULL " // the schedule isn't mailed
            + "AND CURRENT_TIMESTAMP >= ps.mailingDate " // after mailing date
            + "AND CURRENT_TIMESTAMP < ps.reminderDate " // before reminder date
         + ") OR ( "
            + "ps.reminder IS NULL " // the schedule isn't reminded
            + "AND CURRENT_TIMESTAMP >= ps.reminderDate " // after the reminder date
         + ") "
      + ")"),


and the hibernate generated query using hibernate.show_sql to verify the output:
Code:
select distinct operation0_.id as id1_2_, operation0_.subscription_batch_id as subscri12_2_, operation0_.bounce_reason as bounce_r2_2_, operation0_.date as date3_2_, operation0_.email as email4_2_, operation0_.mail_id_high as mail_id_5_2_, operation0_.mail_id_low as mail_id_6_2_, operation0_.operation_name as operatio7_2_, operation0_.pass as pass8_2_, operation0_.patient_name as patient_9_2_, operation0_.subscription_notification as subscri10_2_, operation0_.surgery_id as surgery13_2_, operation0_.unsubscribe as unsubsc11_2_
from webscore.operation operation0_
inner join webscore.protocol protocols1_ on operation0_.id=protocols1_.operation_id
inner join webscore.protocol_schedule protocolsc2_ on protocols1_.id=protocolsc2_.protocol_id
where (
   exists (
      select 'found'
      from webscore.license license3_
      where license3_.surgery_id=operation0_.surgery_id
      and license3_.revoked=false
      and (
         CURRENT_DATE between license3_.start_date and license3_.expiry_date
      )
   )
)
and protocols1_.cancelled=false
and protocolsc2_.submitted=false
and protocolsc2_.expired=false
and CURRENT_TIMESTAMP<=protocolsc2_.schedule_date
and (
   (
      protocolsc2_.mailed is null
   )
   and CURRENT_TIMESTAMP>=protocolsc2_.mailing_date
   and CURRENT_TIMESTAMP<protocolsc2_.reminder_date
   or (
      protocolsc2_.reminder is null
   )
   and CURRENT_TIMESTAMP>=protocolsc2_.reminder_date
)


The OR statement at the end is positioned incorrectly with respect to the brackets and the last 3 AND statements.
I was expecting it to look like this:
Code:
and (
   (
      protocolsc2_.mailed is null
      and CURRENT_TIMESTAMP>=protocolsc2_.mailing_date
      and CURRENT_TIMESTAMP<protocolsc2_.reminder_date
   )
   or (
      protocolsc2_.reminder is null
      and CURRENT_TIMESTAMP>=protocolsc2_.reminder_date
   )
)


Am I mistaken, or is this a bug?


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Sun Jan 19, 2014 12:07 am 
Newbie

Joined: Thu Jan 16, 2014 8:46 am
Posts: 4
Is this forum still in use, or is it just Kitchen design spam now?
Is there anywhere I can get support for this problem?


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Tue Jan 21, 2014 8:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, I'm sorry for the kitchen spam; doing our best to ban them, but they're aggressive :-(

I think you're right, that looks like a nasty bug.
Assuming you're using a recent version, please report it on JIRA?

https://hibernate.atlassian.net/browse/HHH

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Tue Jan 21, 2014 8:20 am 
Newbie

Joined: Thu Jan 16, 2014 8:46 am
Posts: 4
Have done already thanks.
https://hibernate.atlassian.net/browse/HQLPARSER-35
Hope it's the right section.


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Wed Jan 22, 2014 4:35 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Thanks!

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Mon Feb 03, 2014 12:15 am 
Newbie

Joined: Thu Jan 16, 2014 8:46 am
Posts: 4
Should I expect someone to have a look at this problem, or isn't this important enough?
Is there any way for me to get the JIRA actioned a little faster?
After all, this is a major non compliance and I would have expected someone to at least have had a look.


Top
 Profile  
 
 Post subject: Re: JPQL to SQL not translated correctly
PostPosted: Mon Feb 03, 2014 7:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Remember the project is largely run by volunteers, and each one has his own priorities.
Since this looks like an important one, it's very likely that one of us (full-time developers) will take it, but I can't make time promises.
Customers get an SLA, and unfortunately we seem to have all hands full at this time; I'll ping my colleagues as this saddens me but your safest bet is to contribute a fix.

If you provide a fix and it follows our development guidelines (style, unit tests), it will be merged quickly.

http://hibernate.org/orm/contribute/

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.