-->
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.  [ 6 posts ] 
Author Message
 Post subject: QBE and QBC returning bogus results
PostPosted: Sun Mar 06, 2005 8:34 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Hi,

I have a simplified version of te auction database from the "Hibernate In Action" book, with a 1-many relationship between item and bid. I have 6 items in my item table, 5 with the description of "old guitar" and one with the description of "Strat". When I do a query by constraint on the description "old guitar" i get a list of 15 items! Each item is repeated 3 times. When I do a query by example on the same criteria, I get no items returned. However, a QBE on the price of the item (12000.0F) returns 2 items, even though there is only one in the table.

What's going on?

Thanks!

Code:
[b]Hibernate version: 2.1.8[/b]

[b]Mapping documents: [u]Auction.hbm.xml[/u]
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping SYSTEM "hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
   <class name="domain.Item" table="item">
      <id name="id" unsaved-value="0" column="ITEM_ID" type="long">
         <generator class="identity" />
      </id>
      <set name="bids" cascade="all-delete-orphan" outer-join="true" inverse="true">
         <key column="ITEM_ID" />
         <one-to-many class="domain.Bid" />
      </set>
      <property name="description" type="java.lang.String" column="description" />
      <property name="price" type="float" column="price" />
   </class>
   <class name="domain.Bid" table="bid">
      <id name="id" unsaved-value="0" column="BID_ID" type="long">
         <generator class="identity" />
      </id>
      <many-to-one name="item" column="ITEM_ID" class="domain.Item" />
      <property name="amount" column="amount" type="float" />
   </class>
</hibernate-mapping>
[u]hibernate.cfg.xml[/u]
<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- properties -->
        <property name="connection.username">root</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
        <property name="connection.password"></property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="show_sql">true</property>
<!-- mapping files -->
        <mapping resource="domain/Auction.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

[b]Code between sessionFactory.openSession() and session.close():
   public void testRetrieveByQBC() throws HibernateException {
      Session session = getSession();
      Criteria criteria = session.createCriteria(Item.class);
      criteria.add(Expression.eq("description", "old guitar"));
      List guitars = criteria.list();
      assertNotNull(guitars);
      assertTrue(guitars.size() > 0);
      System.out.println("Size of QBC list: " + guitars.size());
      closeSession();
   }
   public void testRetrieveByQBEDesc() throws HibernateException
   {
      Session session = getSession();
      Item item = new Item();
      item.setDescription("old guitar");
      Criteria criteria = session.createCriteria(Item.class);
      criteria.add(Example.create(item));
      List result = criteria.list();
      assertNotNull(result);
      assertTrue(result.size() > 0);
      System.out.println("Size of QBE list: " + result.size());
      closeSession();
   }
[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using: MySQL 4.0.20a[/b]

[b]The generated SQL (show_sql=true):
[u]QBC[/u]
Hibernate: select this.ITEM_ID as ITEM_ID1_, this.description as descript2_1_, this.price as price1_, bids1_.ITEM_ID as ITEM_ID__, bids1_.BID_ID as BID_ID__, bids1_.BID_ID as BID_ID0_, bids1_.ITEM_ID as ITEM_ID0_, bids1_.amount as amount0_ from item this left outer join bid bids1_ on this.ITEM_ID=bids1_.ITEM_ID where this.description=?
[u]QBE[/u]
Hibernate: select this.ITEM_ID as ITEM_ID1_, this.description as descript2_1_, this.price as price1_, bids1_.ITEM_ID as ITEM_ID__, bids1_.BID_ID as BID_ID__, bids1_.BID_ID as BID_ID0_, bids1_.ITEM_ID as ITEM_ID0_, bids1_.amount as amount0_ from item this left outer join bid bids1_ on this.ITEM_ID=bids1_.ITEM_ID where (this.description=? and this.price=?)

[/b]

[b]Debug level Hibernate log excerpt:[/b]

[/code][/u]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 06, 2005 8:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a FAQ


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 06, 2005 8:45 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Ok, I'll look thru the FAQs again.... would have been a good thing to include in the book, tho.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 06, 2005 9:29 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Ok, throw me a bone here. I can't find any reference to this in the FAQs. Where do I need to look?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 06, 2005 9:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
http://www.hibernate.org/117.html#A11


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 06, 2005 9:43 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Thanks Gavin!


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