Question

JPA 2.1 has been released recently and a new feature seems to be on conditions.

I found it mentioned in some blogs and the Eclipselink documentation.

How can I make use of this?

I have two entities linked to each other with @OneToMany and @JoinColumn. However I have to filter out some of the second entities.

The blog sample shows:

SELECT s.name, COUNT(p)
  FROM Suppliers s LEFT JOIN s.products p
    ON p.status = 'inStock'
 GROUP BY s.name

How can I make use of this for my mappings?

Was it helpful?

Solution

The ON clause is for queries, not mappings.

If you want to add an additional criteria to a mapping, this is not something that JPA supports in the spec.

With EclipseLink you can do this using a DescriptorCustomizer and setting the mapping's selectionCriteria.

See, http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top