Query query = session.createQuery("from Customer where name like ?"); query.setParameter(0, "%John%"); Listcustomers = query.list();
Query query = session.createQuery("from Product where price > :minPrice"); query.setParameter("minPrice", 10.0); ListIn this example, we create a Hibernate query to retrieve all products whose price is greater than a specified minimum value. We set a named parameter using the setParameter method, passing in the parameter name ('minPrice') and the value to be substituted (10.0 in this case). We then execute the query and retrieve the results. Both of these examples use the setParameter method from the org.hibernate.Query class, which is part of the Hibernate library. To use this method, you need to import the necessary classes and add the Hibernate library to your project's classpath.products = query.list();