0

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?

Udo Held
  • 12,314
  • 11
  • 67
  • 93

1 Answers1

1

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

James
  • 17,965
  • 11
  • 91
  • 146
  • I already guessed those are two very different animals. I wanted to stay free for implementation dependent stuff, but I will have a look at it. – Udo Held Jul 11 '13 at 13:13