tags:

views:

44

answers:

1

When using hibernate, I get a ConcurrentModificationException when I have an entity A that contains an embedded collection of B, where each element of B contains a collection of Strings. In other words, A is an entity class and B is an embeddable class. A has a collection of B. Each B has it's own collection of Strings.

This appears to be a known hibernate bug (HHH-4313), described at http://opensource.atlassian.com/projects/hibernate/browse/HHH-4313

Unfortunately for me, the bug priority is low, and it hasn't been resolved since it was filed back on March 29th of 07. So I don't have high hopes that it will be resolved any time soon. However, I have been unable to find a workaround without converting B to an entity class, which I really don't want to do.

Has anyone found a workaround for this particular bug?

A: 

The "bug" here is the fact that ConcurrentModificationException is thrown instead of something more graceful - not the fact that collections of elements do not support embedded collections.

The latter is a design consideration and I wouldn't hold my breath waiting for it go get fixed; that most likely won't happen until next major (and I do mean major) release - or lat all.

The underlying problem is that collection of elements does not impose any restrictions on individual element being identifiable by itself; thus there's no clear way to map the association from embedded collection to parent. There are some scenarios where that may be possible (lists / sets with well-defined business key) but ultimately in order for this to be possible you're looking at introducing entity semantics to collection elements without actually making them entities, which seems rather pointless.

The solution is simple - make your B a real entity. You can very much maintain collection element-like lifecycle using all-delete-orphan cascade style and you'll get to enjoy embedded collections to boot.

ChssPly76