0

I have a parent entity which has oneToMany relationship with childEntity. Using Parent Specification I am able to filter parent records based on attributes of childEntity But while loading parentEntity It loads all child entities without any specification applied on childEntity. Can anyone please help out with how can I filter child entities while loading parent entity.

yagyavrat
  • 107
  • 2
  • 11
  • This is not possible with JPA. Why do you want to do that? What is your use case? – Simon Martinelli Aug 09 '18 at 08:53
  • @SimonMartinelli have a parent entity and child entity, with oneToMany Relationship. Client enters filters on the attributes of parent and child. I need to give data to user based on the filters in input. Example : Suppose person(parent) owns cars(child entity). Now I want to list all person having a specific car(or model) along with that car details(e.g: registration number, year of purchase). – yagyavrat Aug 12 '18 at 09:48
  • Two things: 1. Please share your code. I'm trying to figure out how to query for parents based on child values, and having a hard time finding examples. This would have been a nice question to refer to if you provide a complete question compliant with the community guidelines, in which case I could upvote to get you some of those juicy points. 2. I'm pretty sure the reason you're seeing this is because you're selecting the parent entity. Therefore the fetch is going to follow from the matched parent down the graph. That parent has more than just the child you matched on, so more child results. – Stephan Sep 06 '18 at 16:10

0 Answers0