-->
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.  [ 3 posts ] 
Author Message
 Post subject: paramters in HQL
PostPosted: Mon Mar 06, 2006 12:16 pm 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
Hibernate version:
3.0

Mapping documents:
Code:
<hibernate-mapping>
  <class table="document" name="com.xxx.Document" proxy="com.xxx.Document">
    <id name="id" type="long" column="idDocument">
      <generator class="increment"/>
    </id>
    <set cascade="all" lazy="true" name="extractionSections">
      <key column="idDocument" not-null="true" foreign-key="documentIdx"/>
      <one-to-many class="com.xxx.ExtractionSection"/>
    </set>
  </class>
</hibernate-mapping>

Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):
Code:
select parentfeat8_.idParentFeature as col_0_0_, feature1_.idFeature as col_1_0_, feature1_.featureName as col_2_0_ from document document0_ inner join extractionsection extraction2_ on document0_.idDocument=extraction2_.idDocument inner join extraction extraction3_ on extraction2_.idExtraction=extraction3_.idExtraction inner join section section4_ on extraction2_.idSection=section4_.idSection inner join positionedfeature pparentFeatureositioned5_ on extraction2_.idExtractionSection=positioned5_.idExtractionSection inner join feature feature6_ on positioned5_.idFeature=feature6_.idFeature inner join featureHierarchy parentfeat7_ on feature6_.idFeature=parentfeat7_.idFeature, feature feature1_ inner join featureHierarchy parentfeat8_ on feature1_.idFeature=parentfeat8_.idFeature where document0_.idDocument=? and feature1_.idFeature=parentfeat7_.idParentFeature and parentfeat8_.idParentFeature=?


Code used:
Code:
          String query = "SELECT rpfeat.parentFeature.id, rfeat.id, rfeat.name, false " +
          "FROM Document document " +
          ", Feature rfeat " +
          "JOIN document.extractionSections exsec " +
          "JOIN exsec.extraction ex " +
          "JOIN exsec.section as sec " +
          "JOIN exsec.positionedFeatures as pfeat " +
          "JOIN pfeat.feature as feat " +
          "JOIN feat.parentFeatures as parents " +
          "JOIN rfeat.parentFeatures as rpfeat " +
          "WHERE document.id=? " +
          "AND rfeat.id = parents.parentFeature.id " +
          "AND rpfeat.parentFeature=? ";

          Query q = getSession().createQuery(query);
          q.setLong(0, 73l);
          q.setLong(1, 5684911768528200454l);
          q.list();


Problem:

When I build my query, if I use
Code:
"idDocument=73"

it does work (I get some results)
but if I use:
Code:
"idDocument=?"

and
Code:
"query.setLong(0, 73l)"

it does not work anymore (I get an empty set)

If I execute the generated SQL directly in a MySQL console, everything is ok. And I do use another parameter (parentFeature) which works perfectly.

Could someone explain me what I did wrong ?
Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 2:48 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 5:34 pm
Posts: 25
I would name your paramenters. Try the following.

Code:

"idDocument= :id"

query.setLong("id", new Long(73l));



Didn't double check the method arguments/syntax but I believe this is what you are after.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 5:12 am 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
Thanks for your reply, but I did try to use named parameters but without much more success.


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