HHH-1830 - Error during parse query on MS SQL

This commit is contained in:
Gail Badner 2016-08-25 22:06:46 -07:00 committed by Vlad Mihalcea
parent 3d27fa88f5
commit f07cdde352
3 changed files with 49 additions and 10 deletions

View File

@ -609,6 +609,18 @@ public class JoinSequence {
}
}
public JoinSequence copyForCollectionProperty() {
JoinSequence copy = this.copy();
copy.joins.clear();
Iterator<Join> joinIterator = this.joins.iterator();
while (joinIterator.hasNext()) {
Join join = joinIterator.next();
copy.addJoin(join.getAssociationType(), join.getAlias(),
JoinType.INNER_JOIN, join.getLHSColumns());
}
return copy;
}
@Override
public String toString() {
final StringBuilder buf = new StringBuilder();

View File

@ -622,7 +622,7 @@ class FromElementType {
Map enabledFilters = fromElement.getWalker().getEnabledFilters();
String subquery = CollectionSubqueryFactory.createCollectionSubquery(
joinSequence.copy().setUseThetaStyle( true ),
joinSequence.copyForCollectionProperty().setUseThetaStyle( true ),
enabledFilters,
collectionPropertyMapping.toColumns( tableAlias, propertyName )
);

View File

@ -236,7 +236,15 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
session.getTransaction().commit();
assertEquals( 1, Constructor.getConstructorExecutionCount() );
assertEquals( new Constructor( constructor.getId(), true, true, constructor.getId() + 1, constructor.getId() + "foo" ), result );
assertEquals(
new Constructor(
constructor.getId(),
true,
true,
constructor.getId() + 1,
constructor.getId() + "foo"
), result
);
session.close();
}
@ -700,7 +708,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
.setParameter( "name", null )
.list();
assertEquals( 1, results.size() );
results = s.createQuery( "from Human where name.first = :firstName and ( :name is null or name.last = :name )" )
results = s.createQuery( "from Human where name.first = :firstName and ( :name is null or name.last = cast(:name as string) )" )
.setParameter( "firstName", "Bono" )
.setParameter( "name", null )
.list();
@ -720,7 +728,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
.setParameter( "intVal", null )
.list();
assertEquals( 5, results.size() );
results = s.createQuery( "from Human where :intVal is null or intValue = :intVal" )
results = s.createQuery( "from Human where :intVal is null or intValue is null" )
.setParameter( "intVal", null )
.list();
assertEquals( 5, results.size() );
@ -1052,7 +1060,11 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
// resolved to a "id short cut" when part of the order by clause -> no inner join = no weeding out...
checkCounts( "from SimpleAssociatedEntity e order by e.owner", 2, "implicit-join in order-by clause" );
// resolved to a "id short cut" when part of the group by clause -> no inner join = no weeding out...
checkCounts( "select e.owner.id, count(*) from SimpleAssociatedEntity e group by e.owner", 2, "implicit-join in select and group-by clauses" );
checkCounts(
"select e.owner.id, count(*) from SimpleAssociatedEntity e group by e.owner",
2,
"implicit-join in select and group-by clauses"
);
s = openSession();
s.beginTransaction();
@ -1750,6 +1762,21 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue(jiraKey = "HHH-1830")
public void testAggregatedJoinAlias() {
Session s = openSession();
s.getTransaction().begin();
s.createQuery(
"select p.id, size( descendants ) " +
"from Animal p " +
"left outer join p.offspring descendants " +
"group by p.id" )
.list();
s.getTransaction().commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-1464" )
public void testQueryMetadataRetrievalWithFetching() {