I would like to load collections with a criteria or hql query (due to security reasons) created dynamically at runtime (depending on the current user).
The queries can be quite complex, and since Filters do not support joins they aren't really an option.
I tried to implement a custom CollectionPersister which uses an extended CriteriaLoader. This sort of works, but includes some dirty hacks like reading QueryParameters by reflection and calling postInstantiate() again after manually setting the collectionPersisters & suffixes to the loader. Also the Criteria API is already deprecated.
I tried a custom QueryLoader as well, but could not get it to work.
Another approach was to implement my own InitializeCollectionEventListener, which just fetches the entities I need and then add them to the PersistentSet's tempList via reflection, avoiding the entire Loader classes. This seems to work too, but I don't know what side effects this might have?
- Do you know another way how to achieve this? - What might go wrong with my second approach? Anything else I need to initialize there apart from the PersistentCollection?
Thanks!
|