-->
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.  [ 5 posts ] 
Author Message
 Post subject: Query issue - dublicate objects returning from the database
PostPosted: Wed Mar 31, 2004 7:22 pm 
Newbie

Joined: Wed Mar 31, 2004 6:42 pm
Posts: 4
I am performing a simple query agains an Oracle database. Here is the code between session and close

Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();   
      Session session = sessionFactory.openSession();
      Transaction tx = session.beginTransaction();
                   
      List result = session.find("from CatalogEntry_Keyword where KEYWORD_LOWER = ?", key.toLowerCase(), Hibernate.STRING);
       
      tx.commit();
      session.close();


This brings me back a nice list of CatalogEntry_Keyword objects. The list is accurate in terms of the number of objects it returns. The trouble is, it returns a list of the same objects (in terms of the retrieved data) rather than unique objects. They seem to be mapped to the first row it finds, then duplicates that data for each row in the query result set. The mapping document for this class is as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   <class name="com.sandboxsystems.lmsextendedAPI.model.CatalogEntry_Keyword" table="LMM.CATALOGENTRY_KEYWORD">
      <id name="OID" type="char" column="OID">      
         <generator class="assigned" />
      </id>
      <property name="Lang" column="LANG" />
      <property name="Keyword_Lower" column="KEYWORD_LOWER" />
      <property name="Keyword" column="KEYWORD" />
      <property name="CatalogEntry_OID" column="CATALOGENTRY_OID" />
   </class>
</hibernate-mapping>
<!-- parsed in 0ms -->


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:33 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
Use HQL syntax in find method:
Code:
List result = session.find("from com.sandboxsystems.lmsextendedAPI.model.CatalogEntry_Keyword where Keyword_Lower=?", key.toLowerCase(), Hibernate.STRING);

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, the correct HQL would be:

Code:
from CatalogEntry_Keyword cek where cek.Keyword_Lower=?


But that is probably not the problem.


I suggest you get out your debugger and reolve your own issues on this one. The forum should not be used for trivial problems that you have not taken the time to investigate fully.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 12:55 pm 
Newbie

Joined: Wed Mar 31, 2004 6:42 pm
Posts: 4
gavin wrote:
Actually, the correct HQL would be:

Code:
from CatalogEntry_Keyword cek where cek.Keyword_Lower=?


But that is probably not the problem.


I suggest you get out your debugger and reolve your own issues on this one. The forum should not be used for trivial problems that you have not taken the time to investigate fully.

Thanks.



Sorry Gavin, new to this technology. I believe my issue is with how I've defined the <ID> for the OID property. This is a straight read from the database, building a list of objects. How would you define the ID to read from the primary key column in the database?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 2:13 pm 
Newbie

Joined: Wed Mar 31, 2004 6:42 pm
Posts: 4
jmcilroy wrote:
gavin wrote:
Actually, the correct HQL would be:

Code:
from CatalogEntry_Keyword cek where cek.Keyword_Lower=?


But that is probably not the problem.


I suggest you get out your debugger and reolve your own issues on this one. The forum should not be used for trivial problems that you have not taken the time to investigate fully.

Thanks.



Sorry Gavin, new to this technology. I believe my issue is with how I've defined the <ID> for the OID property. This is a straight read from the database, building a list of objects. How would you define the ID to read from the primary key column in the database?


Yep, data type problem. Mapped the OID column/property as Character (idiot) instead of String.


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