Spring Data JPA Specification for a OneToMany Relationship
<p>I have a problem with getting List entity Categories using Spring data JPA specifications. I need to get all Categories with their Recipes where <code>Recipe.dateModified</code> greater then some date. I don't know how to create my Predicate which would fill <code>Collection&lt;Recipe&gt;</code> in each category only those recipes that greater than this date.</p>

<pre><code>@Entity    
public class Category {

    private int id;
    private String name;

    @OneToMany(mappedBy = "categories")
    private Collection&lt;Recipe&gt; recipes;
}

@Entity
public class Recipe {

    private int id;
    private String name;

    private Timestamp dateModified;

}
</code></pre>

<p>In <code>CategoryService</code> I getting <code>List&lt;Category&gt;</code> using Specification:</p>

<pre><code>@Service   
public class CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;

    public List&lt;Category&gt; findAll(Date date) {
        return categoryRepository.findAll(where(byDateModified(date)));
    }

}
</code></pre>

<p>I would write Specification like this, but this does not working.</p>

<pre><code>public class RecipeSpec {

    public static Specification&lt;Category&gt; byDateModified(Date date) {
        return (root, query, builder) -&gt; {
            final Join&lt;Category, Recipe&gt; recipe = root.join(Category_.recipes, JoinType.LEFT);
            return builder.greaterThan(recipe.get(Recipe_.dateModified), date);
        };
    }

}
</code></pre>