本文整理了Java中javax.persistence.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:javax.persistence.Query
类名称:Query
[英]Interface used to control query execution.
[中]用于控制查询执行的接口。
代码示例来源:origin: kiegroup/jbpm
@SuppressWarnings("unchecked")
public List<String> findContextIdForEvent(String eventType, String ownerId) {
EntityManager em = emf.createEntityManager();
Query findQuery = em.createNamedQuery("FindProcessInstanceWaitingForEvent")
.setParameter("eventType", eventType).setParameter("ownerId", ownerId);
return findQuery.getResultList();
}
代码示例来源:origin: spring-projects/spring-framework
protected void deleteAllPeopleUsingEntityManager(EntityManager em) {
em.createQuery("delete from Person p").executeUpdate();
}
代码示例来源:origin: hibernate/hibernate-orm
private static boolean hasData(EntityManager entityManager) {
return (((Long) entityManager.createQuery( "select count(a) from Address a" ).getSingleResult()) +
((Long) entityManager.createQuery( "select count(p) from Person p" ).getSingleResult())) > 0;
}
}
代码示例来源:origin: stackoverflow.com
// SQL: SELECT * FROM table LIMIT start, maxRows;
Query q = session.createQuery("FROM table");
q.setFirstResult(start);
q.setMaxResults(maxRows);
代码示例来源:origin: stackoverflow.com
String sql = "SELECT t FROM table t";
Query query = em.createQuery(sql);
query.setFirstResult(firstPosition);
query.setMaxResults(numberOfRecords);
List result = query.getResultList();
代码示例来源:origin: stackoverflow.com
Query empQuery = session.createQuery(hqlQuery);
empQuery.setMaxResults(maxResult);
employees = (List<Employee>) empQuery.list();
for (Employee emp : employees) {
Hibernate.initialize(emp.address);
}
代码示例来源:origin: Impetus/Kundera
/**
* Test positional query.
*/
private void testPositionalQuery()
{
String queryString = "Select min(p.salary) from PersonES p where p.personName = ?1";
Query query = em.createQuery(queryString);
query.setParameter(1, "amit");
List resultList = query.getResultList();
Assert.assertEquals(1, resultList.size());
Assert.assertEquals(100.0, resultList.get(0));
}
代码示例来源:origin: spring-projects/spring-data-examples
@Override
@SuppressWarnings("unchecked")
public List<Employee> findSubordinates(Employee manager) {
return entityManager.createQuery("SELECT u from User u where u.manager = :manager") //
.setParameter("manager", manager) //
.getResultList();
}
}
代码示例来源:origin: spring-projects/spring-integration-samples
@SuppressWarnings("unchecked")
public static List<LoanShark> findLoanSharkEntries(int firstResult, int maxResults) {
return entityManager().createQuery("select o from LoanShark o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() {
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p");
q.getResultList();
assertTrue("Should be open to start with", sharedEntityManager.isOpen());
sharedEntityManager.close();
assertTrue("Close should have been silently ignored", sharedEntityManager.isOpen());
}
代码示例来源:origin: Impetus/Kundera
/**
* Test max aggregation.
*/
private void testMaxAggregation()
{
String queryString = "Select max(p.age) from PersonES p";
Query query = em.createQuery(queryString);
List resultList = query.getResultList();
Assert.assertEquals(1, resultList.size());
Assert.assertEquals(40.0, resultList.get(0));
}
代码示例来源:origin: hibernate/hibernate-orm
final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null );
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new DataPoint( "Brett" ) );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
DataPoint dp = em.find( DataPoint.class, 1 );
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
dp = em.find( DataPoint.class, 1 );
em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery( "delete from DataPoint" ).executeUpdate();
em.getTransaction().commit();
em.close();
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
@Override
public List<FulfillmentGroup> readUnprocessedFulfillmentGroups(int start,
int maxResults) {
Query query = em.createNamedQuery("BC_READ_UNPROCESSED_FULFILLMENT_GROUP_ASC");
query.setFirstResult(start);
query.setMaxResults(maxResults);
return query.getResultList();
}
代码示例来源:origin: kiegroup/jbpm
@Override
protected int getProcessInstancesCount() {
boolean txOwner = false;
if( useTransactions ) {
txOwner = txm.begin();
}
int size = emf.createEntityManager().createQuery( "FROM ProcessInstanceInfo" ).getResultList().size();
if( useTransactions ) {
txm.commit(txOwner);
}
return size;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersons() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertEquals(0, people.size());
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
}
catch (NoResultException ex) {
// expected
}
}
代码示例来源:origin: Impetus/Kundera
/**
* Test delete all.
*/
private void testDeleteAll()
{
persistBooks();
int result = em.createQuery("delete from Book b").executeUpdate();
Assert.assertEquals(4, result);
assertDeleted(T, T, T, T);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test() {
doInJPA( this::sessionFactory, entityManager -> {
Thing thing = new Thing();
entityManager.persist( thing );
entityManager
.createQuery( "update thing set special = :s, version = version + 1" )
.setParameter( "s", "new" )
.executeUpdate();
thing.special = "If I'm flush to the DB you get an OptimisticLockException";
} );
}
代码示例来源:origin: Impetus/Kundera
/**
* @param b
*/
private void testNativeQuery(boolean b)
{
String s = "Select * From " + "\"StudentUUID\"";
EntityManager em = emf.createEntityManager();
Query q = em.createNativeQuery(s, StudentUUID.class);
List<StudentUUID> results = q.getResultList();
Assert.assertNotNull(results);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void deferredQueryWithSingleResult() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager targetEm = mock(EntityManager.class);
Query query = mock(Query.class);
given(emf.createEntityManager()).willReturn(targetEm);
given(targetEm.createQuery("x")).willReturn(query);
given(targetEm.isOpen()).willReturn(true);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.createQuery("x").getSingleResult();
verify(query).getSingleResult();
verify(targetEm).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void deferredQueryWithUpdate() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager targetEm = mock(EntityManager.class);
Query query = mock(Query.class);
given(emf.createEntityManager()).willReturn(targetEm);
given(targetEm.createQuery("x")).willReturn(query);
given(targetEm.isOpen()).willReturn(true);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.createQuery("x").executeUpdate();
verify(query).executeUpdate();
verify(targetEm).close();
}
内容来源于网络,如有侵权,请联系作者删除!