-->
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: generate SQL query for class mapping containing <any>
PostPosted: Thu Sep 15, 2005 3:50 am 
Newbie

Joined: Thu Jan 08, 2004 5:11 am
Posts: 4
Location: France
I've got a problem with an hibernate generated SQL query :
it appears with selects on a class with <any > tag.

The generated SQL doesn't work with Oracle, see details below.

Hibernate version: 3.0.5
Using org.hibernate.dialect.OracleDialect

Mapping documents:
Code:
<class name="Transition"
      table="HISTORIQUECN">
      <id name="id" column="id" type="long">
         <generator class="sequence">
            <param name="sequence">SEQ_HISTORIQUECN</param>
         </generator>
      </id>
      <any name="transitable" id-type="long" meta-type="string">
         <meta-value value="CLT" class="Client" />
         <meta-value value="CTR" class="Contrat" />
         <meta-value value="PRO"   class="PropositionCommerciale" />
         <column name="type" />
         <column name="transitable" />
      </any>
      <property name="dateOperation" column="DATECHANGEMENT" type="date" />
      <many-to-one name="etatAvant" column="ETATAVANT" class="Etat" cascade="none" />
      <many-to-one name="etatApres" column="ETATAPRES" class="Etat" cascade="none" />
      <property name="commentaire" column="COMMENTAIRE" type="string" />
      <many-to-one class="Personne" name="personne" column="PERSONNE" />
   </class>


Code between sessionFactory.openSession() and session.close():
Code:
String query = "select t from Transition t where t.transitable = :transitable order by t.dateOperation desc";
Query hbQuery = session.createQuery(query);
hbQuery.setParameter("transitable", transitable);
Collection result = hbQuery.list();


Full stack trace of any exception that occurs:
a bunch of exceptions due to a java.sql.SQLException

Name and version of the database you are using: Oracle 8.1.7.4.1

The generated SQL (show_sql=true):
Code:
select transition0_.id as id, transition0_.type as type8_, transition0_.transitable as transita3_8_, transition0_.DATECHANGEMENT as DATECHAN4_8_, transition0_.ETATAVANT as ETATAVANT8_, transition0_.ETATAPRES as ETATAPRES8_, transition0_.COMMENTAIRE as COMMENTA7_8_, transition0_.PERSONNE as PERSONNE8_
from HISTORIQUECN transition0_
where (transition0_.type, transition0_.transitable)=? order by datec desc


If, at first sight the query doesn't looks bad, the problem resides in the where clause, Oracle doesn't like the "(field1, field2) = ?" syntax. It gives me an ORA-00920 error : invalid relational operator

If I execute the sql with example values, I get the same error
Code:
select transition0_.id as id, transition0_.type as type8_, transition0_.transitable as transita3_8_, transition0_.DATECHANGEMENT as DATECHAN4_8_, transition0_.ETATAVANT as ETATAVANT8_, transition0_.ETATAPRES as ETATAPRES8_, transition0_.COMMENTAIRE as COMMENTA7_8_, transition0_.PERSONNE as PERSONNE8_
from HISTORIQUECN transition0_
where (transition0_.type, transition0_.transitable)=('CTR', 49006)  order by datec desc

but if I add parenthesis, it works :
Code:
select transition0_.id as id, transition0_.type as type8_, transition0_.transitable as transita3_8_, transition0_.DATECHANGEMENT as DATECHAN4_8_, transition0_.ETATAVANT as ETATAVANT8_, transition0_.ETATAPRES as ETATAPRES8_, transition0_.COMMENTAIRE as COMMENTA7_8_, transition0_.PERSONNE as PERSONNE8_
from HISTORIQUECN transition0_
where (transition0_.type, transition0_.transitable)=(('CTR', 49006))  order by datec desc


Perhaps, the SQL generator should be updated ?


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.