Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Additional Criteria

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source


Additional Criteria

You can add additional criteria to a descriptor's default queries, thereby providing a filtering option. This filtering option, for example, allows you to use an existing additional JOIN expression from a descriptor query manager and allows you to pass parameters to it.

You can specify additional criteria at the Entity or MappedSuperclass level. When specified at the mapped superclass level, it applies to all inheriting entities, unless those entities define their own additional criteria, in which case the additional criteria from the mapped superclass is ignored.

The additional criteria supports any valid JPQL string and must use this as an alias to form the additional criteria, for example,

@Entity
@AdditionalCriteria("this.nut.size = :NUT_SIZE and this.nut.color = :NUT_COLOR")public class Bolt {...}

Additional criteria parameters are accepted and are set through properties on the entity manager factory or on an entity manager. When set on the entity manager, the properties must be set before any query execution and should not be changed for the life span of that entity manager.

Properties set on the entity manager override those similarly named properties set on the entity manager factory.

Additional criteria is not supported with any native queries.

You can specify additional criteria using the @AdditionalCriteria annotation or the <additional-criteria> element, as shown in the following examples.

Examples

@AdditionalCriteria("this.address.city IS NOT NULL")
<additional-criteria>
  <criteria>this.address.city IS NOT NULL</criteria>
</additional-criteria>

Metadata overriding and merging

Additional criteria specified in eclipselink-orm.xml takes precedence over additional criteria specified elsewhere. The order of precedence is as follows:

  1. eclipselink-orm.xml
  2. Mapping file
  3. On the entity class
  4. On a mapped superclass (first one to define one) 

Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...

Back to the top