-->
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: Adding to large Lists quickly?
PostPosted: Sat Jan 12, 2008 11:46 am 
Newbie

Joined: Sat Jan 12, 2008 11:27 am
Posts: 2
I have a List of persisted entities which will grow
very large (perhaps 10000 elements) over time.
Most of the time I will be accessing this List simply
to add another entity using List.add(Object). When
doing this Hibernate loads the entire List (even with
lazy fetching), although strictly speaking you could
persist the added entries just by knowing the size
of the list and adding the new rows to the table.

Is there any way to implement a custom List which
would extend laziness to include cases where
the only operations performed on the List are
additions?

Thanks in advance,
Dan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 5:29 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
dlr137,

Here is one idea: make the relationship "bidirectional", so that you can not only add children to a parent, but do something like child.setParent(parent);

In your mapping files, you have to create a one-to-many relationship from parent to child, and on the child mapping, a many-to-one relationship from child to parent. Mark the parent-to-child with inverse="true".

In this way, you can add a relationship between the two without having to retrieve the whole list of children. You just create a new children and set his parent.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 6:09 pm 
Newbie

Joined: Sat Jan 12, 2008 11:27 am
Posts: 2
Gonzao,

Interesting idea. But how then would the table column corresponding
to the list index get set?

Thanks,
Dan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 6:54 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
In your mapping file you would already have indicated what your list index column would be.
Other than that, you set it on your bean like you would do with any other property.

_________________
Gonzalo Díaz


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.