org.hibernate.transform.DistinctRootEntityResultTransformer Java Examples
The following examples show how to use
org.hibernate.transform.DistinctRootEntityResultTransformer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicFilterTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testManyToManyFilterOnCriteria() { TestData testData = new TestData(); testData.prepare(); Session session = openSession(); session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() ); Product prod = ( Product ) session.createCriteria( Product.class ) .setResultTransformer( new DistinctRootEntityResultTransformer() ) .add( Expression.eq( "id", testData.prod1Id ) ) .uniqueResult(); assertNotNull( prod ); assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() ); session.close(); testData.release(); }
Example #2
Source File: SchedulerDBManager.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private Map<Long, List<TaskData>> loadJobsTasks(Session session, List<Long> jobIds) { Query tasksQuery = session.getNamedQuery("loadJobsTasks") .setParameterList("ids", jobIds) .setReadOnly(true) .setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<TaskData> tasks = tasksQuery.list(); return tasks.stream().collect(Collectors.groupingBy(taskData -> taskData.getJobData().getId())); }
Example #3
Source File: NativeSQLQueriesTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void testSQLQueryInterface() { Session s = openSession(); Transaction t = s.beginTransaction(); Organization ifa = new Organization("IFA"); Organization jboss = new Organization("JBoss"); Person gavin = new Person("Gavin"); Employment emp = new Employment(gavin, jboss, "AU"); s.persist(ifa); s.persist(jboss); s.persist(gavin); s.persist(emp); List l = s.createSQLQuery( getOrgEmpRegionSQL() ) .addEntity("org", Organization.class) .addJoin("emp", "org.employments") .addScalar("regionCode", Hibernate.STRING) .list(); assertEquals( 2, l.size() ); l = s.createSQLQuery( getOrgEmpPersonSQL() ) .addEntity("org", Organization.class) .addJoin("emp", "org.employments") .addJoin("pers", "emp.employee") .list(); assertEquals( l.size(), 1 ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); l = s.createSQLQuery( "select {org.*}, {emp.*} " + "from ORGANIZATION org " + " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" ) .addEntity("org", Organization.class) .addJoin("emp", "org.employments") .setResultTransformer(new DistinctRootEntityResultTransformer()) .list(); assertEquals( l.size(), 2 ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); s.delete(emp); s.delete(gavin); s.delete(ifa); s.delete(jboss); t.commit(); s.close(); }
Example #4
Source File: ASTParserLoadingTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void testResultTransformerScalarQueries() throws Exception { createTestBaseData(); String query = "select an.description as description, an.bodyWeight as bodyWeight from Animal an order by bodyWeight desc"; Session session = openSession(); List results = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).list(); assertEquals( "Incorrect result size", results.size(), 2 ); assertTrue( "Incorrect return type", results.get(0) instanceof Animal ); Animal firstAnimal = (Animal) results.get(0); Animal secondAnimal = (Animal) results.get(1); assertEquals("Mammal #1", firstAnimal.getDescription()); assertEquals("Mammal #2", secondAnimal.getDescription()); assertFalse(session.contains(firstAnimal)); session.close(); session = openSession(); Iterator iter = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).iterate(); assertTrue( "Incorrect result size", iter.hasNext() ); assertTrue( "Incorrect return type", iter.next() instanceof Animal ); session.close(); session = openSession(); ScrollableResults sr = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).scroll(); assertTrue( "Incorrect result size", sr.next() ); assertTrue( "Incorrect return type", sr.get(0) instanceof Animal ); assertFalse(session.contains(sr.get(0))); sr.close(); session.close(); session = openSession(); results = session.createQuery( "select a from Animal a, Animal b order by a.id" ) .setResultTransformer(new DistinctRootEntityResultTransformer()) .list(); assertEquals( "Incorrect result size", 2, results.size()); assertTrue( "Incorrect return type", results.get(0) instanceof Animal ); firstAnimal = (Animal) results.get(0); secondAnimal = (Animal) results.get(1); assertEquals("Mammal #1", firstAnimal.getDescription()); assertEquals("Mammal #2", secondAnimal.getDescription()); session.close(); destroyTestBaseData(); }