-->
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.  [ 8 posts ] 
Author Message
 Post subject: many-to-one set not fully loaded
PostPosted: Fri Aug 05, 2005 12:48 pm 
Newbie

Joined: Thu Jul 14, 2005 8:21 pm
Posts: 9
I'm doing a simple call to myObject.getThings() and the resulting Set has only 954 items in it whereas it should contain 1600. If I run the query that is printed in the log I do get the 1600. Even adding distinct still gives 1600.

I tried stepping through the code and after the query runs and is processed in Loader.doQuery() the hydratedObjects and the returned results both contain 1600. But resluts is then thrown away so I don't know how it manages to assign the Set to myObject but when I get back to MyObject, the Set only has 954 items. What did I do wrong?

When I reduce the expected outcome to like 30 objects it works just fine.

Hibernate version:
3.0.5
Mapping documents:

<hibernate-mapping
>
<class
name="com.MyObject"
>

<id
name="id"
column="ID"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">INTERNAL_ID_SEQ</param>
</generator>
</id>



<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="NAME"
length="100"
not-null="true"
/>

<set
name="things"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>

<key
column="MYOBJECT_ID"
>
</key>

<one-to-many
class="com.Thing"
/>

</set>

</class>

</hibernate-mapping>



<hibernate-mapping
>
<class
name="com.Thing"
>

<id
name="id"
column="ID"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">INTERNAL_ID_SEQ</param>

</generator>
</id>



<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="NAME"
length="100"
not-null="true"
/>

<many-to-one
name="template"
class="com.MyObject"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="MYOBJECT_ID"
/>
</many-to-one>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

MyObject temp = (MyObject)session.load(MyObject.class, Id);
Set things = temp.getThings();
Iterator iter = things.iterator();

at this point, I check the size of things in the debugger and see 954.


Name and version of the database you are using:
Oracle 10g

The log is too big to include.


Top
 Profile  
 
 Post subject: JDBC fetch size
PostPosted: Fri Aug 05, 2005 4:03 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Did you check value of hibernate.jdbc.fetch_size?

http://www.hibernate.org/hib_docs/v3/re ... ation.html


Top
 Profile  
 
 Post subject: most likely
PostPosted: Fri Aug 05, 2005 4:05 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Actually you probably need to set hibernate.max_fetch_depth


Top
 Profile  
 
 Post subject: Re: JDBC fetch size
PostPosted: Fri Aug 05, 2005 4:51 pm 
Newbie

Joined: Thu Jul 14, 2005 8:21 pm
Posts: 9
kgignatyev wrote:
Did you check value of hibernate.jdbc.fetch_size?

http://www.hibernate.org/hib_docs/v3/re ... ation.html



That fetch_size should not have any effect on the total rows returned. If you read my post, the result set does return all the rows. It's just the Set associated with the MyObject that is missing rows.

fetch_depth is completely irrelevant as this is not using a join query. The set is lazy loaded and therefore loaded completely separate from the primary object.


Top
 Profile  
 
 Post subject: Re: many-to-one set not fully loaded
PostPosted: Fri Aug 05, 2005 5:08 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
farmer wrote:
I'm doing a simple call to myObject.getThings() and the resulting Set has only 954 items in it whereas it should contain 1600. If I run the query that is printed in the log I do get the 1600. Even adding distinct still gives 1600.

I tried stepping through the code and after the query runs and is processed in Loader.doQuery() the hydratedObjects and the returned results both contain 1600. But resluts is then thrown away so I don't know how it manages to assign the Set to myObject but when I get back to MyObject, the Set only has 954 items. What did I do wrong?

When I reduce the expected outcome to like 30 objects it works just fine.


I would verify that that the data in your database contains 1600 unique rows based on the equals() method of your Thing object.

Because these are being placed in a Set, duplicates aren't allowed and if your equals() method identifies two rows as equal, only one of them will end up in the set.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: many-to-one set not fully loaded
PostPosted: Fri Aug 05, 2005 6:31 pm 
Newbie

Joined: Thu Jul 14, 2005 8:21 pm
Posts: 9
pksiv wrote:

I would verify that that the data in your database contains 1600 unique rows based on the equals() method of your Thing object.

Because these are being placed in a Set, duplicates aren't allowed and if your equals() method identifies two rows as equal, only one of them will end up in the set.


no luck. I ran: "select distinct name, user_number from Thing" and got the same record count - 1600.

Here's my equals...

public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof Thing) ) return false;
Thing castOther = (Thing) other;
return new EqualsBuilder()
.append(this.getName(), castOther.getName())
.append(this.getUserNumber(), castOther.getUserNumber())
.isEquals();
}


Top
 Profile  
 
 Post subject: Re: many-to-one set not fully loaded
PostPosted: Fri Aug 05, 2005 6:52 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
farmer wrote:
no luck. I ran: "select distinct name, user_number from Thing" and got the same record count - 1600.

Here's my equals...

public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof Thing) ) return false;
Thing castOther = (Thing) other;
return new EqualsBuilder()
.append(this.getName(), castOther.getName())
.append(this.getUserNumber(), castOther.getUserNumber())
.isEquals();
}


In your mapping you do not load userNumber property.

How many records return "select distinct name from Thing" ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 7:16 pm 
Newbie

Joined: Thu Jul 14, 2005 8:21 pm
Posts: 9
It was a data problem. pksiv was right after all. I had supposably identical dbs confused but one had all the same values for userNumber. There were 954 distinct names in the db. (gotta put those constraints on the db).

Thanks!!!


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