-->
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: OutOfMemoryError with indexed Collection
PostPosted: Wed Oct 22, 2003 5:50 am 
Newbie

Joined: Wed Oct 22, 2003 12:30 am
Posts: 3
Location: Sydney, Australia
I think we may have found the cause of an OutOfMemoryError that has been troubling us for some time.

Today we tracked it down to a one-to-many mapping using a List with an index. It would appear that the error was triggered because the value of the index was very large.

Consider the following code in net.sf.hibernate.collection.List:

/**
* @see PersistentCollection#readFrom(ResultSet, CollectionPersister)
*/
public Object readFrom(ResultSet rs, CollectionPersister persister, Object owner)
throws HibernateException, SQLException {

Object element = persister.readElement(rs, owner, session) ;
int index = ( (Integer) persister.readIndex(rs, session) ).intValue();
for ( int i = list.size(); i<=index; i++) {
list.add(i, null);
}
list.set(index, element);
return element;
}

If index is a very large value, say 10,000,000 and the size of the list is small, then a very large number of elements will be added to the list.

Now I am wondering what the purpose of this code is? What is the intent? Is this a bug?

I our case we were able to get around the problem by changing the mapping to not use an index. However, it still looks like a bug to me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 5:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
no, it is not a bug. obviously.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 6:00 am 
Newbie

Joined: Wed Oct 22, 2003 12:30 am
Posts: 3
Location: Sydney, Australia
Gavin,

Sorry, but it is not obvious to me. What is the intention of adding the null objects to the list in the for loop?

Regards,
Keith

P.S. As I'm sure you know, I like Hibernate. I'm just trying to get to the bottom of the problem we experienced. It it's not a bug, fine. I'm simply trying to understand and make a contribution.

_________________
Keith Pitty


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 6:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The value of the index column is interpreted as the actual list index, not just an "ordering". Perhaps what you really want is a Map.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 6:36 am 
Newbie

Joined: Wed Oct 22, 2003 12:30 am
Posts: 3
Location: Sydney, Australia
Ah. Obviously we were using the index inappropriately.

_________________
Keith Pitty


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.