.getResultList(); assertEquals( 1, results.size() );
@Test public void testAuditQueryWithJoinedInheritanceSubclassPropertyProjectionWithRelationTraversal() { // HHH-11383 // This test was requested by the reporter so that we have a test that shows Hibernate is // automatically adding "INNER JOIN EntityA_AUD" despite the fact whether the query uses // the traverseRelation API or not. This test makes sure that if the SQL generation is // changed in the future, Envers would properly fail if so. List results = getAuditReader().createQuery().forEntitiesAtRevision( EntityB.class, 1 ) .addProjection( property( "name" ) ) .traverseRelation( "relationToC", JoinType.INNER ) .add( property( "foo" ).like( "bar" ) ) .getResultList(); assertEquals( 2, results.size() ); }
.addProjection( AuditEntity.property( "age" ) ).addOrder( AuditEntity.property( "age" ).asc() ).getResultList(); assertEquals( "Unexpected number of results", 3, list1.size() ); assertEquals( "Unexpected age at index 0", Integer.valueOf( 20 ), list1.get( 0 ) ); .addOrder( AuditEntity.property( "age" ).asc() ).traverseRelation( "address", JoinType.INNER ).addProjection( AuditEntity.selectEntity( false ) ).getResultList(); assertEquals( "Unexpected number of results", 3, list2.size() ); assertEquals( "Unexpected address at index 0", address1.getId(), list2.get( 0 ).getId() ); .addProjection( AuditEntity.selectEntity( true ) ).addOrder( AuditEntity.property( "number" ).asc() ).getResultList(); assertEquals( "Unexpected number of results", 2, list3.size() ); assertEquals( "Unexpected address at index 0", address1.getId(), list3.get( 0 ).getId() ); .addProjection( AuditEntity.property( "number" ) ).getResultList(); assertEquals( "Unexpected number of results", 3, list4.size() ); final Object[] index0 = list4.get( 0 );
@Test public void testAssociationQueryWithOrdering() { AuditReader auditReader = getAuditReader(); List<Car> cars1 = auditReader.createQuery().forEntitiesAtRevision( Car.class, 1 ).traverseRelation( "owner", JoinType.INNER ).traverseRelation( "address", JoinType.INNER ) .addOrder( AuditEntity.property( "number" ).asc() ).up().addOrder( AuditEntity.property( "age" ).desc() ).getResultList(); assertEquals( "Unexpected number of results", 3, cars1.size() ); assertEquals( "Unexpected car at index 0", ford.getId(), cars1.get( 0 ).getId() ); assertEquals( "Unexpected car at index 1", vw.getId(), cars1.get( 1 ).getId() ); assertEquals( "Unexpected car at index 2", toyota.getId(), cars1.get( 2 ).getId() ); List<Car> cars2 = auditReader.createQuery().forEntitiesAtRevision( Car.class, 1 ).traverseRelation( "owner", JoinType.INNER ).traverseRelation( "address", JoinType.INNER ) .addOrder( AuditEntity.property( "number" ).asc() ).up().addOrder( AuditEntity.property( "age" ).asc() ).getResultList(); assertEquals( "Unexpected number of results", 3, cars2.size() ); assertEquals( "Unexpected car at index 0", vw.getId(), cars2.get( 0 ).getId() ); assertEquals( "Unexpected car at index 1", ford.getId(), cars2.get( 1 ).getId() ); assertEquals( "Unexpected car at index 2", toyota.getId(), cars2.get( 2 ).getId() ); }
@Test public void testAuditQueryWithJoinedInheritanceUsingWithSemanticsOneToOne() { List results = getAuditReader().createQuery().forEntitiesAtRevision( EntityB.class, 1 ) .add( disjunction() .add( property( "name" ).like( "b1" ) ) .add( property( "name" ).like( "b2" ) ) ) .traverseRelation( "relationToD", JoinType.INNER ) .add( property( "foo" ).like( "bar" ) ) .getResultList(); assertEquals( 2, results.size() ); }
@Test public void testAuditQueryWithJoinedInheritanceUsingWithSemanticsManyToOne() { List results = getAuditReader().createQuery().forEntitiesAtRevision( EntityB.class, 1 ) .add( disjunction() .add( property( "name" ).like( "b1" ) ) .add( property( "name" ).like( "b2" ) ) ) .traverseRelation( "relationToC", JoinType.INNER ) .add( property( "foo" ).like( "bar" ) ) .getResultList(); assertEquals( 2, results.size() ); }
@Test public void testAuditQueryWithJoinedInheritanceUsingWithSemanticsToOne() { List results = getAuditReader().createQuery().forEntitiesAtRevision( EntityB.class, 1 ) .add( disjunction() .add( property( "name" ).like( "b1" ) ) .add( property( "name" ).like( "b2" ) ) ) .traverseRelation( "relationToC", JoinType.INNER ) .add( property( "foo" ).like( "bar" ) ) .up() .traverseRelation( "relationToD", JoinType.INNER ) .add( property( "foo" ).like( "bar" ) ) .getResultList(); assertEquals( 2, results.size() ); }
.traverseRelation( "country", JoinType.INNER ) .add( AuditEntity.property( "name" ).eq( "România" ) ) .getResultList(); .getResultList();
.traverseRelation( "address", JoinType.INNER ) .add( AuditEntity.property( "country" ).eq( "România" ) ) .getResultList();