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

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

Line 26: Line 26:
 
You can specify additional criteria using the <tt>@AdditionalCriteria</tt> annotation or the <tt>&lt;additional-criteria&gt;</tt> element, as shown in the following examples.
 
You can specify additional criteria using the <tt>@AdditionalCriteria</tt> annotation or the <tt>&lt;additional-criteria&gt;</tt> element, as shown in the following examples.
  
s parameters to it.
+
==Examples==
 
+
<pre>
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.
+
@AdditionalCriteria("this.address.city IS NOT NULL")
 
+
</pre>
The additional criteria supports any valid JPQL string and must use <tt>this</tt> as an alias to form the additional criteria, for example,
+
  
 
<pre>
 
<pre>
@Entity
+
&lt;additional-criteria&gt;
@AdditionalCriteria("this.nut.size = :NUT_SIZE and this.nut.color = :NUT_COLOR")public class Bolt {...}
+
  &lt;criteria&gt;this.address.city IS NOT NULL&lt;/criteria&gt;
 +
&lt;/additional-criteria&gt;
 
</pre>
 
</pre>
  
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 <tt>@AdditionalCriteria</
+
{{EclipseLink_JPA
 +
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Criteria|Criteria]]
 +
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Native|Native]]
 +
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying|Querying]]
 +
|version=2.2.0 DRAFT}}

Revision as of 11:12, 10 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

@AdditionalCriteria("this.address.city IS NOT NULL")
<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