-->
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.  [ 3 posts ] 
Author Message
 Post subject: Find entities by logged in user context
PostPosted: Wed Jun 22, 2016 11:49 am 
Newbie

Joined: Wed Jun 22, 2016 11:46 am
Posts: 2
I am using Spring Boot and Hibernate and JPA repositories to search data.
I want to filter search results by logged in user's context.

E.G. Find method to return all entities that are owned by logged in user (Assumption is that every entity has a owner.)? I have many JPA methods for filtering and I don't want to edit all of them with an additional constraint. Is it possible to do it dynamically using annotation or something like @Where/@Filter ?


Top
 Profile  
 
 Post subject: Re: Find entities by logged in user context
PostPosted: Thu Jun 23, 2016 3:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
I assume that you are using entity collections heavily, and you want to filter those automatically. You might achieve that with @Where and @Filter to some extent, but I don't think it's the best way to do it.

What you need to do is to use queries instead. Queries are much more flexible than filtering collections, and they can filter just as much info as you need. This requires more work than you have probably expected, but it's the right thing to do.


Top
 Profile  
 
 Post subject: Re: Find entities by logged in user context
PostPosted: Thu Jun 23, 2016 3:59 am 
Newbie

Joined: Wed Jun 22, 2016 11:46 am
Posts: 2
I am using
Code:
org.springframework.data.jpa.domain.Specification;
to make specification and then put specs in repo's find methods. It is more easy than to change all @Queries.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.