Query query = session.createQuery("from Person p where p.age > :age"); query.setInteger("age", 18); query.setFirstResult(0); query.setMaxResults(10); Listpersons = query.list();
Query query = session.createQuery("update Person p set p.name = :name where p.id = :id"); query.setString("name", "Alice"); query.setLong("id", 123); query.setFirstResult(0); int rowsAffected = query.executeUpdate();In this example, we create an update query that updates the name of the Person object with ID 123 to "Alice". We set the first result to 0 since we are not interested in retrieving any results, only updating them. We then execute the update query and store the number of rows affected in the rowsAffected variable. Package library: org.hibernate.Query is part of the Hibernate ORM library.