Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Additional Criteria"

m
Line 27: Line 27:
  
 
==Examples==
 
==Examples==
<pre>
+
 
 +
Example using the annotation:
 +
 
 +
<source lang="java">
 
@AdditionalCriteria("this.address.city IS NOT NULL")
 
@AdditionalCriteria("this.address.city IS NOT NULL")
</pre>
+
</source>
 +
 
 +
Example using XML:
  
<pre>
+
<source lang="xml">
&lt;additional-criteria&gt;
+
<additional-criteria>
   &lt;criteria&gt;this.address.city IS NOT NULL&lt;/criteria&gt;
+
   <criteria>this.address.city IS NOT NULL</criteria>
&lt;/additional-criteria&gt;
+
</additional-criteria&>
</pre>
+
</source>
  
  

Revision as of 09:33, 24 March 2011

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

Example using the annotation:

@AdditionalCriteria("this.address.city IS NOT NULL")

Example using XML:

<additional-criteria>
  <criteria>this.address.city IS NOT NULL</criteria>
</additional-criteria&>


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

Back to the top