Skip to Content
Java EE 8 Application Development
book

Java EE 8 Application Development

by David R. Heffelfinger
December 2017
Intermediate to advanced
372 pages
8h 46m
English
Packt Publishing
Content preview from Java EE 8 Application Development

Updating data with the Criteria API

When the JPA Criteria API was initially added to JPA 2.0, it only supported selecting data from the database. Modifying existing data was not supported.

JPA 2.1, introduced in Java EE 7, added support for updating database data via the CriteriaUpdate interface; the following example illustrates how to use it:

package net.ensode.javaee8book.criteriaupdate.namedbean; 
 
//imports omitted for brevity 
 
@Named 
@RequestScoped 
public class CriteriaUpdateDemoBean { 
 
    @PersistenceContext 
    private EntityManager entityManager; 
 
    @Resource 
    private UserTransaction userTransaction; 
 
    private int updatedRows; 
 
    public String updateData() { 
        String retVal = "confirmation"; 
 
        try { 
 
            userTransaction.begin(); 
            insertTempData(); 
 
 CriteriaBuilder ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java EE 8 Development with Eclipse

Java EE 8 Development with Eclipse

Ram Kulkarni
Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Jonathan Wetherbee, Massimo Nardone, Chirag Rathod, Raghu Kodali

Publisher Resources

ISBN: 9781788293679Supplemental Content