-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is this a bug in SQL generation from HQL?
PostPosted: Fri Apr 28, 2006 5:11 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2
Mapping documents:
<?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>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="pinnacle.datavo.context.Ortholog" table="ORTHOLOG" schema="PINNACLE">
<id name="id" type="long">
<column name="ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="gene1" class="pinnacle.datavo.context.Gene" fetch="select">
<column name="GENE_1" precision="22" scale="0" />
</many-to-one>

<many-to-one name="gene2" class="pinnacle.datavo.context.Gene" fetch="select">
<column name="GENE_2" precision="22" scale="0" />
</many-to-one>

<property name="percentIdentity" type="double">
<column name="PERCENT_IDENTITY" precision="10" scale="0" />
</property>

<property name="quality" type="string">
<column name="QUALITY" length="50" ></column>
</property>

</class>
</hibernate-mapping>

<?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>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="pinnacle.datavo.context.Gene" table="GENE" schema="PINNACLE">
<id name="id" type="long">
<column name="ID"/>

<generator class="seqhilo">
<param name="sequence">sq_gene_id</param>

<param name="max_lo">2</param>
</generator>
</id>
<property name="buildId" type="string">
<column name="BUILD_ID" length="50"/>
</property>
<property name="externalGeneId" type="string">
<column name="EXTERNAL_GENE_ID" length="50"/>
</property>
<property name="organism" type="string">
<column name="ORGANISM" length="50"/>
</property>
<set name="geneTranscriptProteins" inverse="true">
<key>
<column name="GENE_ID" precision="22" scale="0"/>
</key>
<one-to-many class="pinnacle.datavo.context.GeneTranscriptProtein"/>
</set>

<set name="orthologs" inverse="true">
<key>
<column name="GENE_1" precision="22" scale="0"/>
</key>
<one-to-many class="pinnacle.datavo.context.Ortholog"/>
</set>

</class>
</hibernate-mapping>

Name and version of the database you are using:
Oracle 10g


The problem:
I code up the following HQL:

select distinct o
from Ortholog o
where
(o.gene1.id = :geneID
and o.gene2.organism = :organism)
or
(o.gene2.id = :geneID
and o.gene1.organism =:organism)


Notice how there are two queries that are essentially unioned by the or clause (I would also do this as a union, but hibernate doesn't support that, and I'm trying to avoid leaving HQL).

THe generated SQL is:

select
distinct ortholog0_.ID as ID5_,
ortholog0_.GENE_1 as GENE2_5_,
ortholog0_.GENE_2 as GENE3_5_,
ortholog0_.PERCENT_IDENTITY as PERCENT4_5_,
ortholog0_.QUALITY as QUALITY5_
from
PINNACLE.ORTHOLOG ortholog0_,
PINNACLE.GENE gene1_,
PINNACLE.GENE gene2_
where
ortholog0_.GENE_1=gene2_.ID
and ortholog0_.GENE_2=gene1_.ID
and (
ortholog0_.GENE_1=?
and gene1_.ORGANISM=?
or ortholog0_.GENE_2=?
and gene2_.ORGANISM=?
)

Notice how the parenthesis that I put between the two sets of statments is missing? It should be (logic 1) OR (logic 2). HQL -> SQL seems to have it mangled.

Is this a bug? Or is my HQL off? Should I be doing some kind of sub query?

For reference, the correct SQL should be:
select distinct o.*
from ortholog o, gene g1, gene g2
where o.gene_1 = g1.id
and o.gene_2 = g2.id
and (
(g1.id = ? and g2.organism = ?)
or
(g2.id = ? and g1.organism = ?)
)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 5:12 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
I suspect that it's just not implemented yet - see this comment in the HQL grammar: http://fisheye.jboss.org/viewrep/~raw,r ... mmar/hql.g

Code:
// level 0 - the basic element of an expression
primaryExpression
   :   identPrimary ( options {greedy=true;} : DOT^ "class" )?
   |   constant
   |   COLON^ identifier
   // TODO: Add parens to the tree so the user can control the operator evaluation order.
   |   OPEN! (expressionOrVector | subQuery) CLOSE!
   |   PARAM^ (NUM_INT)?
   ;


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