Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - Manipulating collection post load

We are trying to filter\manipulate Persistent Collection based upon the objects it contains (filter out specific entries).

Since this manipulation will be performed on a large number of different objects containing different collections it must be as generic as possible. Filtering on HQL\SQL level is not an option since it will be impossible to maintain. This means it must be performed after the collection was loaded and initialized. We are currently using many of the Hibernate Events to handle single objects, so we tried listening on the InitializeCollectionEvent. But as it turns out, most of our collections are initialized using HQL Fetch so this event won't be raised for them.

Is there any other Hibernate Event that we can use?

Any other place where the Collections are processed after they are loaded?

We are using Hibernate 4.1.7 .

like image 997
Nir Avatar asked Feb 13 '17 17:02

Nir


1 Answers

I think it's not a good idea to filter collection on server side, when the collection was loaded. If you do that it means smth goes wrong, rethink you db model or entity structure. One of the best way to filter collection - use HQL. Or you can either use @Where or @Loader, @Filter.

like image 147
idmitriev Avatar answered Oct 19 '22 21:10

idmitriev