-->
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.  [ 1 post ] 
Author Message
 Post subject: @OrderColumn and huge list of items
PostPosted: Thu Jun 24, 2010 9:57 am 
Newbie

Joined: Fri Dec 11, 2009 10:44 am
Posts: 3
Hi Guys,

I need your help ! I try to create listings of products with lots of items (100 k).
Here my first approach :
ProductList *<----- Many2Many -----> Product
Code:
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name = "list_items",
        inverseJoinColumns = { @JoinColumn(name = "product_id")},
        joinColumns = { @JoinColumn(name = "list_id")})
@IndexColumn(name = "item_index", base = 1, nullable = false )
@LazyCollection(LazyCollectionOption.EXTRA)
@BatchSize(size=50)
private List<Product> products = new LinkedList<Product>();


Good Hibernate managed the item index for me !
But when I add a product in a list of products, hibernate load all the products in the list (lazy loading)
list.getProducts().add(item);
see : http://stackoverflow.com/questions/3085 ... e-database

My second idea was to create a new entity ListItem for the relation between list and products.
ProductList <--- ManyToOne -- ListItem -- ManyToOne --> Product
Code:
create table list_items (
        product_id integer not null,
        list_id integer not null,
        item_index integer not null,
        primary key (list_id, item_index)
    )

It solves the loading problem : I can persist a new ListItem entity without loading hundred of products.
But how to manage the item_index ? How to generated the item position ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.