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