-->
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.  [ 1 post ] 
Author Message
 Post subject: Lack of parentheses with hsql query
PostPosted: Tue Feb 13, 2007 4:21 am 
Newbie

Joined: Fri Nov 24, 2006 11:58 am
Posts: 1
Hi.

I have a problem with not being able to generate the right parentheses from a hql query.

The HQL is:

Code:
    from PersistentClass pc
    where
      (
        pc.value = value1
        and pc.note = value2
      )
     
      or
      (
        pc.value = case pc.liar
              when true then pc.note
              else value3
              end
      )
     
      and pc.value = 1110


and the generated SQL has no brackets whatsoever, which changes the meaning of the query:

Code:
select
  persistent0_.id as id6_,
  persistent0_.value as value6_,
  persistent0_.liar as liar6_,
  persistent0_.note as note6_
from
  PersistentClass persistent0_
where
  persistent0_.value=value1
  and persistent0_.note=value2
  or persistent0_.value=case persistent0_.liar
   when 1 then persistent0_.note
   else value3
  end
  and persistent0_.value=1110


Am I doing something or did I encounter an unsupported situation in HQL?

Thank you,

Robert

Hibernate version:
3.2.2 ga

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
       
        <mapping resource="org/example/PersistentClass.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.example">
  <class name="PersistentClass">

    <id name="id">
      <generator class="native" />
    </id>
   
    <property name="value"/>
    <property name="liar"/>
    <property name="note"/>
  </class>
 
  <query name="testQuery">
    from PersistentClass pc
    where
      (
        pc.value = value1
        and pc.note = value2
      )
     
      or
      (
        pc.value = case pc.liar
              when true then pc.note
              else value3
              end
      )
     
      and pc.value = 1110
   
  </query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Not applicable

Full stack trace of any exception that occurs:

Not applicable

Name and version of the database you are using:

MySQL 5.0.27-standard-log

The generated SQL (show_sql=true):

Code:
select
  persistent0_.id as id6_,
  persistent0_.value as value6_,
  persistent0_.liar as liar6_,
  persistent0_.note as note6_
from
  PersistentClass persistent0_
where
  persistent0_.value=value1
  and persistent0_.note=value2
  or persistent0_.value=case persistent0_.liar
   when 1 then persistent0_.note
   else value3
  end
  and persistent0_.value=1110


Debug level Hibernate log excerpt:

Not applicable


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

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.