-->
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.  [ 4 posts ] 
Author Message
 Post subject: doInHibernate returns doubles
PostPosted: Mon Sep 29, 2008 9:51 am 
Newbie

Joined: Sun Mar 09, 2008 7:04 pm
Posts: 5
Hey,

I'm getting a strange list size using HQL which I just don't get. When I run the generated SQL (which I can see is used in my debugger), the database returns 3 results. However, doInHibernate(), which uses this HQL, return 7 rows, that is, it returns doubles of each row in the database.

The code including the Hql looks like that:

Code:
HibernateTemplate ht = getHibernateTemplate();
HibernateCallback callback = new HibernateCallback() {
   
   public Object doInHibernate(Session session)
         throws HibernateException {

      String query = "from Note as note where note.agreementRef = :agreementRef and note.noteTypeRef = :noteType order by note.created desc ";
      Query queryObject = session.createQuery(query.toString());
      
      queryObject.setParameter("agreementRef", agreementRef);
      queryObject.setParameter("noteType", noteType);
      
      return queryObject.list();
   }
};
   
List<Note> list = (List<Note>) ht.execute(callback);


The Note hbm.xml mapping file looks like that:

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="what.ever.model.note" default-lazy="true">
   <class name="what.ever.model.note.Note" table="NOTES">
      <cache usage="nonstrict-read-write" />
      
      <id name="id" column="ID" type="java.lang.Integer" unsaved-value="null">
         <generator class="sequence">
            <param name="sequence">NOTES_SEQ</param>
         </generator>
      </id>
      
      <many-to-one name="noteTypeRef" column="NOTE_TYPE_ID_FK"
         class="what.ever.model.note.NoteType" fetch="join" lazy="false" not-null="true" />   
   
      <many-to-one name="agreementRef" column="AGREEMENT_ID_FK"
         class="what.ever.model.agreement.Agreement" fetch="select" not-null="true" />
   
      <property name="note" column="NOTE" type="java.lang.String" />
      <property name="userName" column="USER_NAME" type="java.lang.String" />
      <property name="created" column="CREATED" type="java.util.Date" />      
      <property name="createdBy" column="CREATED_BY" type="java.lang.String" length="100" />
      
   </class>
</hibernate-mapping>



...and I should probably add that the Agreement and NoteType hbm.xml files do not contain references to Note.

The generated SQL looks like that:

Code:
select
      note0_.ID as ID29_,
      note0_.NOTE_TYPE_ID_FK as NOTE2_29_,
      note0_.AGREEMENT_ID_FK as AGREEMENT3_29_,
      note0_.NOTE as NOTE29_,
      note0_.USER_NAME as USER5_29_,
      note0_.CREATED as CREATED29_,
      note0_.CREATED_BY as CREATED7_29_
  from
      NOTES note0_
  where
      note0_.AGREEMENT_ID_FK=?
      and note0_.NOTE_TYPE_ID_FK=?
  order by
      note0_.CREATED desc


I'm using Hibernate 3.2.4, Spring 2.5.5 and Oracle database 9.2.

So, any ideas why I get 7 rows instead of 3?

Thanks,

/U


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 6:41 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
Have you tried running it on a different database? Are you sure there aren't 7 entries in your db?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 1:43 am 
Newbie

Joined: Sun Mar 09, 2008 7:04 pm
Posts: 5
Yeah, I'm sure there's only 3 entries. These 7 ones are not unique: they are doubles of the 3 that are in the database - first and second rows shows twice, and the third row shows three times. Strange right?

/U


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2008 6:03 am 
Newbie

Joined: Sun Mar 09, 2008 7:04 pm
Posts: 5
Well, I finally solved the problem. It was obviously not Hibernate's fault - it was mine...forgot to commit when I deleted rows in SQL developer. When i run the query in SQL Developer - it shows the resault as if I actually deleted rows, but the application ignored the uncommited data of course.

commit,

/U


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