Java javax.persistence.EntityManager createQuery is a method that creates a query object using the entity manager. The query object allows us to execute a query against the persistent storage used by an entity manager.
Query query = entitymanager.createQuery( "Select e from Employee e" );
List list = (List)query.getResultList( );
In this example, we are creating a query that selects all employees from the persistent storage. We then execute the query using the getResultList() method to retrieve a list of employees.
Query query = entitymanager.createQuery( "Select e.name from Employee e where e.salary > :salary" ); query.setParameter("salary", 50000);
List list = (List)query.getResultList( );
In this example, we are creating a query that selects the name of all employees whose salary is greater than a specified value. We use the setParameter() method to set the value of the salary parameter, and then execute the query using the getResultList() method to retrieve a list of employee names.
javax.persistence.EntityManager is part of the Java Persistence API (JPA) library, which is typically included in Java EE containers or can be downloaded separately as a library from Maven or other repositories.
Java EntityManager.createQuery - 30 examples found. These are the top rated real world Java examples of javax.persistence.EntityManager.createQuery extracted from open source projects. You can rate examples to help us improve the quality of examples.