From 51074eb9a083460e8ac9c026135e03ea5497277d Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 1 Apr 2021 11:07:28 -0500 Subject: [PATCH] re-enable tests re-organize some tests continuing with o.h.test.hql fixed bug in JPA model building with dynamic entities added NavigablePath#getUnaliasedLocalName to aid in resolving ModelParts as part of SQM->SQL --- .../metamodel/internal/MetadataContext.java | 4 +- .../model/domain/AbstractManagedType.java | 16 ++- .../model/domain/ManagedDomainType.java | 1 + .../org/hibernate/query/NavigablePath.java | 10 ++ .../sqm/sql/BaseSqmToSqlAstConverter.java | 20 ++- .../domain/SqmPolymorphicRootDescriptor.java | 6 + .../test/any/hbm}/ComplexPropertyValue.java | 2 +- .../test/any/hbm}/IntegerPropertyValue.java | 2 +- .../orm/test/any/hbm/Properties.hbm.xml | 62 ++++++++ .../hql => orm/test/any/hbm}/PropertySet.java | 2 +- .../test/any/hbm}/PropertyValue.java | 2 +- .../test/any/hbm}/StringPropertyValue.java | 2 +- .../test/hql/ASTParserLoadingTest.java | 132 +++++++++++++++--- .../junit4/BaseCoreFunctionalTestCase.java | 13 +- 14 files changed, 239 insertions(+), 35 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{test/hql => orm/test/any/hbm}/ComplexPropertyValue.java (96%) rename hibernate-core/src/test/java/org/hibernate/{test/hql => orm/test/any/hbm}/IntegerPropertyValue.java (95%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/Properties.hbm.xml rename hibernate-core/src/test/java/org/hibernate/{test/hql => orm/test/any/hbm}/PropertySet.java (96%) rename hibernate-core/src/test/java/org/hibernate/{test/hql => orm/test/any/hbm}/PropertyValue.java (90%) rename hibernate-core/src/test/java/org/hibernate/{test/hql => orm/test/any/hbm}/StringPropertyValue.java (95%) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index e9d86c0920..ed293c9f19 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -386,7 +386,9 @@ public class MetadataContext { final Component cidValue = (Component) persistentClass.getIdentifier(); final Iterator cidPropertyItr = cidValue.getPropertyIterator(); - AbstractIdentifiableType idType = (AbstractIdentifiableType) entityTypes.get( cidValue.getOwner().getMappedClass() ); + assert cidValue.isEmbedded(); + + AbstractIdentifiableType idType = (AbstractIdentifiableType) entityTypesByEntityName.get( cidValue.getOwner().getEntityName() ); Set idAttributes = idType.getIdClassAttributesSafely(); if ( idAttributes == null ) { idAttributes = new HashSet<>( cidValue.getPropertySpan() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java index 52d0678c14..af835a651f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java @@ -157,8 +157,7 @@ public abstract class AbstractManagedType } if ( getSuperType() != null ) { - attribute = getSuperType().findAttribute( name ); - //noinspection RedundantIfStatement + attribute = getSuperType().findAttributeInSuperTypes( name ); if ( attribute != null ) { return attribute; } @@ -174,6 +173,19 @@ public abstract class AbstractManagedType return null; } + @Override + public PersistentAttribute findAttributeInSuperTypes(String name) { + final PersistentAttribute local = findDeclaredAttribute( name ); + if ( local != null ) { + return local; + } + + if ( superType != null ) { + return superType.findAttributeInSuperTypes( name ); + } + + return null; + } @Override public PersistentAttribute findSubTypesAttribute(String name) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java index 6b0a4735d1..af15f18ecb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java @@ -53,6 +53,7 @@ public interface ManagedDomainType extends SimpleDomainType, ManagedType findAttribute(String name); PersistentAttribute findSubTypesAttribute(String name); + PersistentAttribute findAttributeInSuperTypes(String name); SingularPersistentAttribute findSingularAttribute(String name); PluralPersistentAttribute findPluralAttribute(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/query/NavigablePath.java b/hibernate-core/src/main/java/org/hibernate/query/NavigablePath.java index 47e82f482a..f507fbcdf3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/NavigablePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/NavigablePath.java @@ -19,6 +19,7 @@ public class NavigablePath implements DotIdentifierSequence { private final NavigablePath parent; private final String fullPath; + private final String unaliasedLocalName; private final String identifierForTableGroup; public NavigablePath(NavigablePath parent, String navigableName) { @@ -29,9 +30,11 @@ public class NavigablePath implements DotIdentifierSequence { // various things such as criteria paths and fetch profile association paths if ( IDENTIFIER_MAPPER_PROPERTY.equals( navigableName ) ) { this.fullPath = parent != null ? parent.getFullPath() : ""; + this.unaliasedLocalName = ""; this.identifierForTableGroup = parent != null ? parent.getIdentifierForTableGroup() : ""; } else { + this.unaliasedLocalName = navigableName; if ( parent != null ) { final String parentFullPath = parent.getFullPath(); this.fullPath = StringHelper.isEmpty( parentFullPath ) @@ -55,6 +58,7 @@ public class NavigablePath implements DotIdentifierSequence { public NavigablePath(String rootName, String alias) { this.parent = null; this.fullPath = alias == null ? rootName : rootName + "(" + alias + ")"; + this.unaliasedLocalName = StringHelper.unqualify( rootName ); identifierForTableGroup = rootName; } @@ -70,9 +74,11 @@ public class NavigablePath implements DotIdentifierSequence { // various things such as criteria paths and fetch profile association paths if ( IDENTIFIER_MAPPER_PROPERTY.equals( navigableName ) ) { this.fullPath = parent != null ? parent.getFullPath() : ""; + this.unaliasedLocalName = ""; identifierForTableGroup = parent != null ? parent.getFullPath() : ""; } else { + this.unaliasedLocalName = property; if ( parent != null ) { final String parentFullPath = parent.getFullPath(); this.fullPath = StringHelper.isEmpty( parentFullPath ) @@ -109,6 +115,10 @@ public class NavigablePath implements DotIdentifierSequence { return parent == null ? fullPath : StringHelper.unqualify( fullPath ); } + public String getUnaliasedLocalName() { + return unaliasedLocalName; + } + public String getFullPath() { return fullPath; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index d8cf8b3638..3b942cd6e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -78,7 +78,6 @@ import org.hibernate.query.QueryLogging; import org.hibernate.query.SemanticException; import org.hibernate.query.TemporalUnit; import org.hibernate.query.UnaryArithmeticOperator; -import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterBindings; @@ -3628,9 +3627,16 @@ public abstract class BaseSqmToSqlAstConverter extends Base @Override public Expression visitPluralAttributeSizeFunction(SqmCollectionSize function) { final SqmPath pluralPath = function.getPluralPath(); - final PluralAttributeMapping mappingModelExpressable = (PluralAttributeMapping) determineValueMapping( - pluralPath ); - final FromClauseAccess parentFromClauseAccess = getFromClauseAccess(); + + final TableGroup parentTableGroup = getFromClauseAccess().getTableGroup( pluralPath.getNavigablePath().getParent() ); + assert parentTableGroup != null; + + final PluralAttributeMapping collectionPart = (PluralAttributeMapping) parentTableGroup.getModelPart().findSubPart( + pluralPath.getNavigablePath().getUnaliasedLocalName(), + null + ); + assert collectionPart != null; + final QuerySpec subQuerySpec = new QuerySpec( false ); pushProcessingState( new SqlAstQueryPartProcessingStateImpl( @@ -3641,7 +3647,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base ) ); try { - final TableGroup tableGroup = mappingModelExpressable.createRootTableGroup( + final TableGroup tableGroup = collectionPart.createRootTableGroup( pluralPath.getNavigablePath(), null, true, @@ -3672,8 +3678,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base subQuerySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, expression ) ); subQuerySpec.applyPredicate( - mappingModelExpressable.getKeyDescriptor().generateJoinPredicate( - parentFromClauseAccess.findTableGroup( pluralPath.getNavigablePath().getParent() ), + collectionPart.getKeyDescriptor().generateJoinPredicate( + parentTableGroup, tableGroup, SqlAstJoinType.INNER, getSqlExpressionResolver(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java index 30c853a073..e6c564a441 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java @@ -163,6 +163,12 @@ public class SqmPolymorphicRootDescriptor implements EntityDomainType { return commonAttributes.get( name ); } + @Override + public PersistentAttribute findAttributeInSuperTypes(String name) { + // there are effectively no super-types + return null; + } + @Override public void visitAttributes(Consumer> action) { commonAttributes.values().forEach( (Consumer) action ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ComplexPropertyValue.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/ComplexPropertyValue.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/hql/ComplexPropertyValue.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/ComplexPropertyValue.java index 32d0cd1127..8049b5978b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ComplexPropertyValue.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/ComplexPropertyValue.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.test.hql; +package org.hibernate.orm.test.any.hbm; import java.util.HashMap; import java.util.Iterator; import java.util.Map; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/IntegerPropertyValue.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/IntegerPropertyValue.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/hql/IntegerPropertyValue.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/IntegerPropertyValue.java index a418f05b27..91758cdcea 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/IntegerPropertyValue.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/IntegerPropertyValue.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.test.hql; +package org.hibernate.orm.test.any.hbm; /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/Properties.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/Properties.hbm.xml new file mode 100644 index 0000000000..59f5672384 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/Properties.hbm.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/PropertySet.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertySet.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/hql/PropertySet.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertySet.java index 4dc923cf37..688ce8ffd6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/PropertySet.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertySet.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.test.hql; +package org.hibernate.orm.test.any.hbm; import java.util.HashMap; import java.util.Map; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/PropertyValue.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertyValue.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/hql/PropertyValue.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertyValue.java index b6aea87c47..eaeda10762 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/PropertyValue.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/PropertyValue.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.test.hql; +package org.hibernate.orm.test.any.hbm; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/StringPropertyValue.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/StringPropertyValue.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/hql/StringPropertyValue.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/StringPropertyValue.java index d1f8ab2c54..7c6fcf5e1d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/StringPropertyValue.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/hbm/StringPropertyValue.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.test.hql; +package org.hibernate.orm.test.any.hbm; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java index 2e3f9c0f09..b4e7afe56e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java @@ -53,12 +53,17 @@ import org.hibernate.loader.MultipleBagFetchException; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; +import org.hibernate.orm.test.any.hbm.IntegerPropertyValue; +import org.hibernate.orm.test.any.hbm.PropertySet; +import org.hibernate.orm.test.any.hbm.PropertyValue; +import org.hibernate.orm.test.any.hbm.StringPropertyValue; import org.hibernate.query.Query; import org.hibernate.query.SemanticException; import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.internal.QuerySqmImpl; import org.hibernate.query.sqm.tree.domain.SqmPath; +import org.hibernate.query.sqm.tree.expression.SqmFunction; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.query.sqm.tree.select.SqmSelection; import org.hibernate.stat.QueryStatistics; @@ -77,6 +82,8 @@ import org.hibernate.orm.test.cid.LineItem; import org.hibernate.orm.test.cid.LineItem.Id; import org.hibernate.orm.test.cid.Order; import org.hibernate.orm.test.cid.Product; + +import org.junit.After; import org.junit.Test; import org.hamcrest.CoreMatchers; @@ -85,6 +92,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.notNullValue; import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; @@ -116,27 +124,109 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { private List createdAnimalIds = new ArrayList<>(); + @After + public void cleanUpTestData() { + inTransaction( + (session) -> { + session.createQuery( "from Animal" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from User" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Zoo" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from StateProvince" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Joiner" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Foo" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from One" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Many" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from SimpleAssociatedEntity" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from SimpleEntityWithAssociation" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from HeresAnotherCrazyIdFieldName" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from MoreCrazyIdFieldNameStuffEntity" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Image" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from ComponentContainer" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from VariousKeywordPropertyEntity" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Constructor" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from ProductLine" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Model" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from LineItem" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Product" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Order" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Customer" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from PropertySet" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Commento" ).list().forEach( + (animal) -> session.delete( animal ) + ); + session.createQuery( "from Marelo" ).list().forEach( + (animal) -> session.delete( animal ) + ); + } + ); + } @Override protected boolean isCleanupTestDataRequired() { - return true; + return false; } @Override public String[] getMappings() { return new String[] { - "hql/Animal.hbm.xml", - "hql/FooBarCopy.hbm.xml", - "hql/SimpleEntityWithAssociation.hbm.xml", - "hql/CrazyIdFieldNames.hbm.xml", - "hql/Image.hbm.xml", - "hql/ComponentContainer.hbm.xml", - "hql/VariousKeywordPropertyEntity.hbm.xml", - "hql/Constructor.hbm.xml", + "/org/hibernate/test/hql/Animal.hbm.xml", + "/org/hibernate/test/hql/FooBarCopy.hbm.xml", + "/org/hibernate/test/hql/SimpleEntityWithAssociation.hbm.xml", + "/org/hibernate/test/hql/CrazyIdFieldNames.hbm.xml", + "/org/hibernate/test/hql/Image.hbm.xml", + "/org/hibernate/test/hql/ComponentContainer.hbm.xml", + "/org/hibernate/test/hql/VariousKeywordPropertyEntity.hbm.xml", + "/org/hibernate/test/hql/Constructor.hbm.xml", "batchfetch/ProductLine.hbm.xml", - "cid/Customer.hbm.xml", - "cid/Order.hbm.xml", - "cid/LineItem.hbm.xml", - "cid/Product.hbm.xml", - "any/Properties.hbm.xml", + "/org/hibernate/orm/test/cid/Customer.hbm.xml", + "/org/hibernate/orm/test/cid/Order.hbm.xml", + "/org/hibernate/orm/test/cid/LineItem.hbm.xml", + "/org/hibernate/orm/test/cid/Product.hbm.xml", + "/org/hibernate/orm/test/any/hbm/Properties.hbm.xml", "legacy/Commento.hbm.xml", "legacy/Marelo.hbm.xml" }; @@ -2607,8 +2697,18 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { sqmStatement = (SqmSelectStatement) q.unwrap( QuerySqmImpl.class ).getSqmStatement(); selections = sqmStatement.getQuerySpec().getSelectClause().getSelections(); assertThat( selections.size(), is( 2 ) ); - assertThat( selections.get( 0 ), nullValue() ); - assertThat( selections.get( 1 ), is( "avg" ) ); + + assertThat( selections.get( 0 ), notNullValue() ); + assertThat( selections.get( 0 ).getAlias(), nullValue() ); + assertThat( selections.get( 0 ).getSelectableNode(), instanceOf( SqmFunction.class ) ); + assertThat( ( (SqmFunction) selections.get( 0 ).getSelectableNode() ).getFunctionName(), is( "count" ) ); + + assertThat( selections.get( 1 ), notNullValue()); + assertThat( selections.get( 1 ).getAlias(), notNullValue() ); + assertThat( selections.get( 1 ).getAlias(), is( "avg" ) ); + assertThat( selections.get( 1 ).getSelectableNode(), instanceOf( SqmFunction.class ) ); + assertThat( ( (SqmFunction) selections.get( 1 ).getSelectableNode() ).getFunctionName(), is( "avg" ) ); + s.delete(a); t.commit(); s.close(); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 64f0968b96..de4dedc61e 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -198,10 +198,15 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { String[] mappings = getMappings(); if ( mappings != null ) { for ( String mapping : mappings ) { - configuration.addResource( - getBaseForMappings() + mapping, - getClass().getClassLoader() - ); + if ( mapping.startsWith( "/" ) ) { + configuration.addResource( mapping, getClass().getClassLoader() ); + } + else { + configuration.addResource( + getBaseForMappings() + mapping, + getClass().getClassLoader() + ); + } } } Class[] annotatedClasses = getAnnotatedClasses();