-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using Criteria or HQL to load collections?
PostPosted: Fri Dec 16, 2016 11:53 am 
Newbie

Joined: Fri Dec 16, 2016 11:23 am
Posts: 1
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!


Top
 Profile  
 
 Post subject: Re: Using Criteria or HQL to load collections?
PostPosted: Mon Jan 09, 2017 5:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Just use Criteria API if you need to build entity queries dynamically.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.