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/Release/2.5/JPA21"

Line 1: Line 1:
=== EclipseLink JPA 2.1 ===
+
= EclipseLink JPA 2.1 =
  
 
This page contains a summary of the major features supported in EclipseLink that implements the JPA 2.1 ([http://jcp.org/en/jsr/detail?id=338 JSR 338]) specification requirements.  The features and examples on this page do not represent a complete list.  For more information, please see: the [http://jcp.org/en/jsr/detail?id=338 JSR 338] page.
 
This page contains a summary of the major features supported in EclipseLink that implements the JPA 2.1 ([http://jcp.org/en/jsr/detail?id=338 JSR 338]) specification requirements.  The features and examples on this page do not represent a complete list.  For more information, please see: the [http://jcp.org/en/jsr/detail?id=338 JSR 338] page.
Line 8: Line 8:
 
addition of CriteriaUpdate/CriteriaDelete classes, support for bulkupdate/delete queries has now been added.
 
addition of CriteriaUpdate/CriteriaDelete classes, support for bulkupdate/delete queries has now been added.
  
= Update Example =
+
=== Update Example ===
 
The following example will update the salary and status, of all Employees who make less than 10000$, and give them a raise.
 
The following example will update the salary and status, of all Employees who make less than 10000$, and give them a raise.
  
Line 22: Line 22:
  
  
= Delete Example =
+
=== Delete Example ===
  
 
   CriteriaDelete<Customer> q = cb.createCriteriaDelete(Customer.class);
 
   CriteriaDelete<Customer> q = cb.createCriteriaDelete(Customer.class);

Revision as of 15:08, 2 May 2013

EclipseLink JPA 2.1

This page contains a summary of the major features supported in EclipseLink that implements the JPA 2.1 (JSR 338) specification requirements. The features and examples on this page do not represent a complete list. For more information, please see: the JSR 338 page.


Bulk Update

Until JPA 2.1, performing deletes or updates was not available using the Criteria API. Through the addition of CriteriaUpdate/CriteriaDelete classes, support for bulkupdate/delete queries has now been added.

Update Example

The following example will update the salary and status, of all Employees who make less than 10000$, and give them a raise.

  CriteriaUpdate<Employee> q = cb.createCriteriaUpdate(Employee.class);
  Root<Employee> emp = q.from(Employee.class);
  .set(e.get(Employee_.salary), cb.prod(e.get(Employee_.salary), 1.1f))
  .set(e.get(Employee_.status), "full_time")
  .where(cb.lt(emp.get(Emploee_.salary), 10000));


The following Java Persistence query language update statement is equivalent.

  UPDATE Employee e SET e.salary = e.salary * 1.1, e.status = "full_time" WHERE e.salary < 10000


Delete Example

  CriteriaDelete<Customer> q = cb.createCriteriaDelete(Customer.class);
  Root<Customer> c = q.from(Customer.class);
  q.where(cb.equal(c.get(Customer_.status), "inactive"),
  cb.isEmpty(c.get(Customer_.orders)));


The following Java Persistence query language delete statement is equivalent.

  DELETE FROM Customer c
    WHERE c.status = 'inactive'
    AND c.orders IS EMPTY

Back to the top