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/Querying/JPQL"

m (JPQL)
m (JPQL)
Line 33: Line 33:
 
The persistence context is not updated to reflect results of update and delete operations. If you use a transaction-scoped persistence context, you should either execute the bulk operation in a transaction all by itself, or be the first operation in the transaction (see [[Introduction%20to%20EclipseLink%20Transactions (ELUG)|Introduction to EclipseLink Transactions]]). That is because any entity actively managed by the persistence context will remain unaware of the actual changes occurring at the database level.
 
The persistence context is not updated to reflect results of update and delete operations. If you use a transaction-scoped persistence context, you should either execute the bulk operation in a transaction all by itself, or be the first operation in the transaction (see [[Introduction%20to%20EclipseLink%20Transactions (ELUG)|Introduction to EclipseLink Transactions]]). That is because any entity actively managed by the persistence context will remain unaware of the actual changes occurring at the database level.
  
For more information and examples, see the following:
+
{{EclipseLink_Spec
 +
|section=Chapter 4 "Query Language"
 +
}}
  
* Section 4.10 "Bulk Update and Delete Operations" of the [http://jcp.org/en/jsr/detail?id=220 JPA Specification]
+
For more information and examples, see the following:
* Chapter 4 "Query Language" of the [http://jcp.org/en/jsr/detail?id=220 JPA Specification]
+
 
* [[#What You May Need to Know About Querying with Java Persistence Query Language|What You May Need to Know About Querying with Java Persistence Query Language]]
 
* [[#What You May Need to Know About Querying with Java Persistence Query Language|What You May Need to Know About Querying with Java Persistence Query Language]]
* [[EclipseLink/UserGuide/Queries (ELUG)|Queries]]
+
* [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying|Queries]]
* [[Introduction%20to%20EclipseLink%20Queries%20(ELUG)#Named Queries|Named Queries]]
+
* [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Named Queries|Named Queries]]
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA

Revision as of 15:02, 16 June 2010

JPQL

You may define queries in metadata annotations or the XML descriptor.

You can use update and delete queries to persist your changes with JP QL.

You can perform bulk update of entities with the UPDATE statement. This statement operates on a single entity type and sets one or more single-valued properties of the entity subject to the condition in the WHERE clause. Update queries provide an equivalent to the SQL UPDATE statement, but with JP QL conditional expressions.

This example demonstrates how to use an update query to give employees a raise. The WHERE clause contains the conditional expression.

Update Query

 UPDATE Employee e
 SET e.salary = 60000
 WHERE e.salary = 50000

You can perform bulk removal of entities with the DELETE statement. Delete queries provide an equivalent to the SQL DELETE statement, but with JP QL conditional expressions.

This example demonstrates how to use a delete query to remove all employees who are not assigned to a department. The WHERE clause contains the conditional expression.

Delete Query

 DELETE FROM Employee e
 WHERE e.department IS NULL

Elug note icon.png

Note: Delete queries are polymorphic: any entity subclass instances that meet the criteria of the delete query will be deleted. However, delete queries do not honor cascade rules: no entities other than the type referenced in the query and its subclasses will be removed, even if the entity has relationships to other entities with cascade removes enabled.


The persistence context is not updated to reflect results of update and delete operations. If you use a transaction-scoped persistence context, you should either execute the bulk operation in a transaction all by itself, or be the first operation in the transaction (see Introduction to EclipseLink Transactions). That is because any entity actively managed by the persistence context will remain unaware of the actual changes occurring at the database level.

Elug javaspec icon.gif

For more information, see Chapter 4 "Query Language" in the JPA Specification.

For more information and examples, see the following:

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

Back to the top