nordborg wrote:
It is not allowed to change the id of an existing object. So even if you can get rid of the LazyInitializationException Hibernate will complain later about the id change. Instead, you'll need to load the object with the new id and change the reference.
Hi. Cannot agree with you.
In my previous projects JSF updated ids and this was saved to database without any problems! The main difference is that I used eager fetching (I didn't manage to enable proxies there, but the parent entities quantity was relatively small and I could afford additional joins), not proxies and worked with detached Hibernate objects (not copies) in my UI. So, the UI framework changed the id of related entity and then I called session.saveOrUpdate(entity) and the entity was
saved together with new links to other entities! I didn't have to manage copies, create new referenced objects and so on - the full cycle was: get the entity with its parents, show on UI, let the user edit select html tags to update references (JSF calls setId() on this) and then save the entity to database. Everything is very transparentely and convenient, Hibernate didn't worry about setting Id at all...
But with proxies I see two ways:
1. create deep (!) copies of all just selected entities and give them to UI so that avoid Hibernate lazy initialization on update of reference id.
2. Use jsf request scope instead of view one for UI and use plenty of hidden fields in the page.
Both ways are not good and very burdensome, so it's interesting to know about users experience with proxies in this situation...