I had a similar problem. But in my case, no
attribute was involved.
What I had was a bidirectional many-to-one association. When I wanted to edit the parent object, what I was doing was storing only an array of ids in my
Struts form.
When I received the request, I was loading each child from Hibernate, creating a new parent object and populating its collection with the children objects before calling a saveOrUpdate method on the parent.
The problem cause, as far as I understood, is that my children objects were backreferencing the parent. So, when I loaded them, I loaded the parent too into my Hibernate session. But when I was updating, I was using a detached copy of the parent. There were actually two version of the parent object, one attached to the session and one not. This is probably why Hibernate complained.
There are two solutions:
- either you load the parent object before updating it
- or you make your association unidirectional.