diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java index 8c727e54a6..25888d4f86 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java @@ -101,7 +101,7 @@ public class MetamodelBuilder { } private EntityTypeImpl locateOrBuildEntityType(EntityBinding binding) { - EntityTypeImpl entityType = entityTypeMap.get( binding.getClassReference() ); + EntityTypeImpl entityType = entityTypeByNameMap.get( binding.getEntityName() ); if ( entityType == null ) { entityType = buildEntityType( binding ); } @@ -122,6 +122,7 @@ public class MetamodelBuilder { ); entityTypeMap.put( javaType, entityType ); + entityTypeByNameMap.put( entityBinding.getEntityName(), entityType ); return entityType; } @@ -235,7 +236,7 @@ public class MetamodelBuilder { processSuperType( descriptor, entityBinding ); final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( descriptor ) - ? entityTypeMap.get( descriptor.getClassReference() ) + ? entityTypeByNameMap.get( descriptor.getName() ) : mappedSuperclassTypeMap.get( descriptor.getClassReference() ); applyIdMetadata( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index 3582229329..bce807ff7a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -2885,10 +2885,14 @@ public class Binder { } private EntityBinding findOrBindEntityBinding(ValueHolder< Class< ? >> entityJavaTypeValue, String explicitEntityName) { +// final String referencedEntityName = +// bindingContext().qualifyClassName( explicitEntityName != null +// ? explicitEntityName +// : entityJavaTypeValue.getValue().getName() ); final String referencedEntityName = - bindingContext().qualifyClassName( explicitEntityName != null + explicitEntityName != null ? explicitEntityName - : entityJavaTypeValue.getValue().getName() ); + : entityJavaTypeValue.getValue().getName(); return findOrBindEntityBinding( referencedEntityName ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java index 1f961321d8..6d084816ec 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java @@ -73,6 +73,7 @@ public abstract class AbstractEntitySourceImpl private final EntityElement entityElement; private final String className; private final String entityName; + private final String jpaEntityName; private List subclassEntitySources = new ArrayList(); @@ -87,9 +88,14 @@ public abstract class AbstractEntitySourceImpl this.entityElement = entityElement; this.className = bindingContext().qualifyClassName( entityElement.getName() ); - this.entityName = StringHelper.isNotEmpty( entityElement.getEntityName() ) - ? entityElement.getEntityName() - : className; + if ( StringHelper.isNotEmpty( entityElement.getEntityName() ) ) { + this.entityName = entityElement.getEntityName(); + this.jpaEntityName = entityElement.getEntityName(); + } + else { + this.entityName = className; + this.jpaEntityName = StringHelper.unqualify( className ); + } } @Override @@ -375,7 +381,7 @@ public abstract class AbstractEntitySourceImpl @Override public String getJpaEntityName() { - return null; + return jpaEntityName; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java index 2c7e87fae2..df1593acef 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java @@ -164,7 +164,7 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { @Override public String getReferencedEntityName() { return manyToOneElement.getClazz() != null - ? manyToOneElement.getClazz() + ? bindingContext().qualifyClassName( manyToOneElement.getClazz() ) : manyToOneElement.getEntityName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java index 86ac0e987b..3b03356bd6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java @@ -171,7 +171,7 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { @Override public String getReferencedEntityName() { return oneToOneElement.getClazz() != null - ? oneToOneElement.getClazz() + ? bindingContext().qualifyClassName( oneToOneElement.getClazz() ) : oneToOneElement.getEntityName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java index 333df48107..e2d2f1dffc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java @@ -294,6 +294,7 @@ public class EntityIdentifier { } params.setProperty( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() ); + params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, entityBinding.getJpaEntityName() ); //init the table here instead of earlier, so that we can get a quoted table name //TODO: would it be better to simply pass the qualified table name, instead of diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java index 3978e6367d..ee106f2ef7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java @@ -25,9 +25,10 @@ package org.hibernate.metamodel.spi.relational; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; -import org.hibernate.AssertionFailure; import org.hibernate.dialect.Dialect; /** @@ -41,7 +42,7 @@ import org.hibernate.dialect.Dialect; public abstract class AbstractConstraint implements Constraint { private final TableSpecification table; private String name; - private List columns = new ArrayList(); + private final Map columnMap = new LinkedHashMap(); protected AbstractConstraint(TableSpecification table, String name) { this.table = table; @@ -108,19 +109,19 @@ public abstract class AbstractConstraint implements Constraint { } protected int generateConstraintColumnListId() { - return table.generateColumnListId( columns ); + return table.generateColumnListId( getColumns() ); } public List getColumns() { - return Collections.unmodifiableList( columns ); + return Collections.unmodifiableList( new ArrayList( columnMap.values() ) ); } public int getColumnSpan() { - return columns.size(); + return columnMap.size(); } - protected List internalColumnAccess() { - return columns; + protected Map internalColumnAccess() { + return columnMap; } public void addColumn(Column column) { @@ -137,7 +138,7 @@ public abstract class AbstractConstraint implements Constraint { // ) // ); // } - columns.add( column ); + columnMap.put( column.getColumnName(), column ); } protected boolean isCreationVetoed(Dialect dialect) { diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java index 29a6f26bd0..a9b35d4e8f 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java @@ -95,12 +95,7 @@ public class AssertSourcesTest extends BaseUnitTestCase { assertEquals( User.class.getName(), entitySource.getClassName() ); assertEquals( User.class.getName(), entitySource.getEntityName() ); - if ( HbmMetadataSourceProcessorImpl.class.isInstance( processor ) ) { - assertNull( entitySource.getJpaEntityName() ); - } - else { - assertEquals( StringHelper.unqualify( User.class.getName() ), entitySource.getJpaEntityName() ); - } + assertEquals( StringHelper.unqualify( User.class.getName() ), entitySource.getJpaEntityName() ); assertEquals( EntityMode.POJO, entitySource.getEntityMode() ); assertNull( entitySource.getCaching() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java index b57486dc78..10c4fb7848 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java @@ -33,7 +33,6 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.internal.util.StringHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -133,7 +132,6 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-6790") - @FailureExpectedWithNewMetamodel public void testSequencePerEntity() { // Checking first entity. EntityPersister persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java index c6b4643bc8..fb81cb4aaa 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java @@ -50,7 +50,6 @@ import org.hibernate.test.annotations.id.sequences.entities.Store; import org.hibernate.test.annotations.id.sequences.entities.Tree; import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -298,7 +297,6 @@ public class IdTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-6790") - @FailureExpectedWithNewMetamodel public void testSequencePerEntity() { Session session = openSession(); session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java b/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java index af3333bb32..ed8cdf733e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java @@ -33,7 +33,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel; * * @author Gail Badner */ -//@FailureExpectedWithNewMetamodel public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java b/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java index e8b91ae1e0..f8bf6662e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java @@ -36,7 +36,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Gail Badner */ -//@FailureExpectedWithNewMetamodel public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/BasicSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/BasicSequenceTest.java index be97a227f6..a6a58385e4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/BasicSequenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/BasicSequenceTest.java @@ -40,7 +40,6 @@ import static org.junit.Assert.assertEquals; * @author Steve Ebersole * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@FailureExpectedWithNewMetamodel public class BasicSequenceTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java b/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java index 38eedc1fad..62866d24e2 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java @@ -32,7 +32,6 @@ import org.hibernate.StaleObjectStateException; import org.hibernate.StaleStateException; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -48,7 +47,6 @@ import static org.junit.Assert.fail; value = DialectChecks.DoesRepeatableReadNotCauseReadersToBlockWritersCheck.class, comment = "potential deadlock" ) -@FailureExpectedWithNewMetamodel public class OptimisticLockTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java index 44bf8eab75..79a9fb9d05 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java @@ -41,7 +41,6 @@ import static org.junit.Assert.assertTrue; /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel public class TypedManyToOneTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { @@ -49,6 +48,7 @@ public class TypedManyToOneTest extends BaseCoreFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testCreateQuery() { Customer cust = new Customer(); cust.setCustomerId("abc123"); diff --git a/hibernate-core/src/test/java/org/hibernate/test/typedonetoone/TypedOneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/typedonetoone/TypedOneToOneTest.java index 097ed22ef0..62a8fecee8 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/typedonetoone/TypedOneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/typedonetoone/TypedOneToOneTest.java @@ -30,7 +30,6 @@ import org.junit.Test; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -40,7 +39,6 @@ import static org.junit.Assert.assertTrue; /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel public class TypedOneToOneTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() {