Using the Update query

The Update query will modify one or more stored entities. This query is used to modify the content of a data store. It specifies the fields of the entity to be modified, their new values and which entities to be affected.

Getting ready

The Update query normally will include the Update clause, a Set clause and a Where clause. The Update clause is similar in structure to a Select clause, but uses the UPDATE keyword instead. The Set clause follows and starts with the SET keyword and has an assignment looking expression. The Where clause follows the Set clause.

For example, to update the dosage for a specific type of mediation we can use this query:

UPDATE Medication m SET m.dosage = 6 WHERE m.type = 'ACE'

The Update clause specifies ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.