We're trying to integrate SOLR into hibernate via event-listeners. In the process, we're hitting an issue with our @ManyToMany relationships via @JoinTable. The issue is the event system is not providing access to "what" changed when the relationship is modified, just that the owning entity was modified. This can mean that if the collection has 10,000 items in it, we don't have access to what was added or removed. Currently, there's no easy or clear way to get access to the deltas of changes to a collection update event. The PostCollectionUpdateEventListener provides access to the PersistentCollection, but for a @ManyToMany collection, the only way to guarantee you can access just the items that have been added or removed is to also listen to the PreCollectionUpdateEventListener and compare the collections. You appear to be able to get the orphans (removals) by asking the PersistentCollection for its Orphans. The problem with the Pre/Post issue is that for a collection of 10,000 objects it requires the initialization of all items to properly do a diff (because you can't get at the identifiers). From what I can see this could be solved in a few different ways –
- formally exposing the additions and removals on a PersistentCollection
- allowing subscription to more detailed events that expose the additions and removals
|