Unique Constraint Violations (UVC's) Issue


I have come across a particular problem which I would like if possible an experienced user to confirm, to see if I spotted the problem correctly.

It has to do with UCV’s. The point is that when I am editing an entity via an editor, and nesting several instance/collection data components, I was getting UCV errors.

Then after searching in this forum I found the answer from Konstantin Krivopustov:

that if combining or composing complex screens where nested entities where managed, I should avoid the use of cascading in the JPA level. Fortunately I did that and the issue went away, so didn’t have to struggle much with that.

Just before that, I saw that inside DataManagerBean at the dataCommit() call, the entities in the screen dataContext were committed, and the dataContext does not consider if any of the managed entities (from a persistence context perspective) are indeed a nested instance of any of the other managed instances. Therefore the commit will be attempted twice on an instance if it is a nested entity: the first one as a result of being in the dataContext entity list, and second as a result of a cascading annotation. So after removing the cascade, the problem was gone.

Is that correct? Could anyone confirm? On the other hand I don’t understand why cascading annotations pose a problem. Don’t have a very deep understanding in JPA, but from previous projects I know that entities may be merged, instead of persisted, resulting in the same output, which should avoid aswell the UCV.

If anyone can clarify it I would be thankful.


Carlos Conti.

Hi Carlos,

It’s hard to say why you face a particular UCV without debugging the code which produces it.
Regarding cascade annotations - they are not recommended and we explain why in the docs:

The entities persisted and merged implicitly using such declaration will bypass some system mechanisms. In particular, the EntityStates bean does not detect the managed state correctly and entity listeners are not invoked at all.


Hi Konstantin,

thanks for your response.

Will leave that as is for the time being. Hopefullu no more UCV’s arise.

Carlos Conti.