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: Cannot load multiple objects.
PostPosted: Fri Aug 13, 2004 11:52 am 
Newbie

Joined: Wed Aug 11, 2004 4:48 pm
Posts: 12
Hibernate version: 2.1.6

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.dti.changetracking">

<class name="Location" table="CHANGE_LOCATION">
<id name="id" type="integer">
<generator class="native"/>
</id>
<property name="description" type="string" not-null="false"/>
<property name="active" type="int" not-null="false"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
try{
Transaction tx= hs.beginTransaction();
try{
Query query = hs.createQuery("from Location l where l.description = :d");
query.setString("d", "Moscow");
for (Iterator it = query.iterate(); it.hasNext();) {
Location l = (Location) it.next();
out.println("Location description: " + l.getDescription() + "<br>");
}
tx.commit();
}
catch(Exception e){
tx.commit();
HibernateFactory.closeSession();
throw e;
}


Full stack trace of any exception that occurs:

Name and version of the database you are using:
MS SQL 2000


Debug level Hibernate log excerpt:

I can see following in stdout.log

Hibernate: select location0_.ID as x0_0_ from CHANGE_LOCATION location0_
Hibernate: select location0_.ID as ID0_, location0_.description as descript2_0_, location0_.active as active0_ from CHANGE_LOCATION location0_ where location0_.ID=?

First of all i don't understand why there is a couple queries?
Both of them looks OK.

But as reasult i got expetion message - cannot load (class_name)#(instance number)

I able to load single object using session. But cannot do that with multiple objects. Whats wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 11:58 am 
Newbie

Joined: Wed Aug 11, 2004 4:48 pm
Posts: 12
I just found that using find() work just fine.
What is the difference between using Query and find().
As i can understand both of them will return collection of objects.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Don't use query.iterate() but query.list() - and read the javadocs to understand the difference.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 12:22 pm 
Newbie

Joined: Wed Aug 11, 2004 4:48 pm
Posts: 12
Ok!
Thanks for advise.

I used some samples from hibernate doc. Playing with cats bla-bla-bla.
Jus cut and past code from there, so expected it will work.

Of course i'll read doc, but i need quick start for right now. Intead of it everything is painful, because some inaccuracies everywhere.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 12:48 pm 
Newbie

Joined: Wed Aug 11, 2004 4:48 pm
Posts: 12
It is more interestin, that using list().listIterator() works just fine.
Whats up? In my understanding it must provide similar result!


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.