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-databaseMy 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 ?