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.
Difference between revisions of "EclipseLink/UserGuide/JPA/A additionalcriteria"
m |
m |
||
Line 4: | Line 4: | ||
|category=JPA | |category=JPA | ||
|release=2.4.x}} | |release=2.4.x}} | ||
+ | {| class="simple oac_no_warn" width="100%" | ||
+ | | align="left" valign="top" | '''EclipseLink JPA Extensions Reference Guide'''<br />'''Version 2.4.x'''<br /> | ||
+ | | width="144" align="right" valign="bottom" | | ||
+ | {| class="simple oac_no_warn" width="100%" | ||
+ | | | ||
+ | | align="center" valign="top" | | ||
+ | [http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search] | ||
+ | | align="center" valign="top" | | ||
+ | [[Table_of_Contents| Contents]] | ||
+ | |} | ||
{| class="simple oac_no_warn" width="100%" | {| class="simple oac_no_warn" width="100%" | ||
| align="left" valign="top" | '''EclipseLink JPA Extensions Reference Guide'''<br />'''Version 2.4.x'''<br /> | | align="left" valign="top" | '''EclipseLink JPA Extensions Reference Guide'''<br />'''Version 2.4.x'''<br /> | ||
Line 36: | Line 46: | ||
<span id="sthref8"></span> | <span id="sthref8"></span> | ||
− | '''''' | + | ''' ''' |
===Annotation Elements=== | ===Annotation Elements=== |
Revision as of 15:38, 5 June 2012
EclipseLink JPA Extensions Reference Guide Version 2.4.x |
@AdditionalCriteriaUse
Annotation ElementsTable 2-1 describes this annotation's elements.
Table 2-1 @AdditionalCriteria Annotation Elements
Usage Additional criteria can provide an additional filtering mechanism for queries. This filtering option, for example, allows you to use an existing additional Set additional criteria parameters through properties on the entity manager factory or on the entity manager. Properties set on the entity manager override identically named properties set on the entity manager factory. Properties must be set on an entity manager before executing a query. Do not change the properties for the lifespan of the entity manager.
Examples Specify additional criteria using the
@AdditionalCriteria("this.address.city IS NOT NULL") Example 2-1 shows additional criteria defined for the entity
Example 2-1 Using @AdditionalCriteria Define additional criteria on
package model; @AdditionalCriteria("this.company=:COMPANY") public class Employee { ... } Set the property on the
entityManager.setProperty("COMPANY", "MyCompany"); Example 2-2 illustrates the same example as before, but uses the
Example 2-2 Using <additional-criteria>
<additional-criteria> <criteria>this.address.city IS NOT NULL</criteria> </additional-criteria>
Uses for Additional Criteria Uses for additional criteria include:
Multitenancy In a multitenancy environment, tenants (users, clients, organizations, applications) can share database tables, but the views on the data are restricted so that tenants have access only to their own data. You can use additional criteria to configure such restrictions.
Example 2-3 Multitenancy Example 1 The following example restricts the data for a Billing client, such as a billing application or billing organization:
@AdditionalCriteria("this.tenant = 'Billing'")
Example 2-4 Multitenancy Example 2 The following example could be used in an application used by multiple tenants at the same time. The additional criteria is defined as:
@AdditionalCriteria("this.tenant = :tenant") When the tenant acquires its
Map properties = new HashMap(); properties.put("tenant", "ACME"); EntityManagerFactory emf = Persistence.createEntityManagerFactory(properties); Or
Map properties = new HashMap(); properties.put("tenant", "ACME"); EntityManager em = factory.createEntityManager(properties);
Soft Delete The following example filters data that is marked as deleted (but which still exists in the table) from a query:
@AdditionalCriteria("this.isDeleted = false")
Data History The following example returns the current data from a query, thus filtering out any out-of-date data, for example data stored in a history table.
@AdditionalCriteria("this.endDate is null")
Temporal Filtering The following example filters on a specific date:
@AdditionalCriteria("this.startDate <= :viewDate and this.endDate >= :viewDate")
Shared Table For a shared table, there may be inheritance in the table but not in the object model. For example, a
See Also For more information, see:
|