I think this is a common scenario. Say I have one, many hibernation displays: Category has many Items
Category:
@OneToMany( cascade = {CascadeType.ALL},fetch = FetchType.LAZY) @JoinColumn(name="category_id") @Cascade( value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN ) private List<Item> items;
Item:
@ManyToOne(targetEntity=Category.class,fetch=FetchType.EAGER) @JoinColumn(name="category_id",insertable=false,updatable=false) private Category category;
Everything works perfectly. I use Category to fully manage the Item life cycle. But, when I write the code for updating Category , first I get Category from the database. Then pass it to the user interface. The user will fill in the changed values โโfor the Category and go back. This is where the problem arises: because I only pass Category information, not Items , so the Items collection will be empty. When I call saveOrUpdate , it will clear all associations.
Any suggestion on what is best solved? I think the advantage of the Category Management of Items is that it is easy to maintain the order of Items and not be confused bi-directly.
But what about the situation you just want to update Category ? Download it first and merge?
source share