HHH-7877 : Add support for multiple entity names used with the same Java class

This commit is contained in:
Gail Badner 2012-12-18 17:22:56 -08:00
parent 0c6ab56372
commit 2bee7d5111
16 changed files with 33 additions and 36 deletions

View File

@ -101,7 +101,7 @@ public class MetamodelBuilder {
} }
private EntityTypeImpl locateOrBuildEntityType(EntityBinding binding) { private EntityTypeImpl locateOrBuildEntityType(EntityBinding binding) {
EntityTypeImpl entityType = entityTypeMap.get( binding.getClassReference() ); EntityTypeImpl entityType = entityTypeByNameMap.get( binding.getEntityName() );
if ( entityType == null ) { if ( entityType == null ) {
entityType = buildEntityType( binding ); entityType = buildEntityType( binding );
} }
@ -122,6 +122,7 @@ public class MetamodelBuilder {
); );
entityTypeMap.put( javaType, entityType ); entityTypeMap.put( javaType, entityType );
entityTypeByNameMap.put( entityBinding.getEntityName(), entityType );
return entityType; return entityType;
} }
@ -235,7 +236,7 @@ public class MetamodelBuilder {
processSuperType( descriptor, entityBinding ); processSuperType( descriptor, entityBinding );
final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( descriptor ) final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( descriptor )
? entityTypeMap.get( descriptor.getClassReference() ) ? entityTypeByNameMap.get( descriptor.getName() )
: mappedSuperclassTypeMap.get( descriptor.getClassReference() ); : mappedSuperclassTypeMap.get( descriptor.getClassReference() );
applyIdMetadata( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor ); applyIdMetadata( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor );

View File

@ -2885,10 +2885,14 @@ public class Binder {
} }
private EntityBinding findOrBindEntityBinding(ValueHolder< Class< ? >> entityJavaTypeValue, String explicitEntityName) { private EntityBinding findOrBindEntityBinding(ValueHolder< Class< ? >> entityJavaTypeValue, String explicitEntityName) {
// final String referencedEntityName =
// bindingContext().qualifyClassName( explicitEntityName != null
// ? explicitEntityName
// : entityJavaTypeValue.getValue().getName() );
final String referencedEntityName = final String referencedEntityName =
bindingContext().qualifyClassName( explicitEntityName != null explicitEntityName != null
? explicitEntityName ? explicitEntityName
: entityJavaTypeValue.getValue().getName() ); : entityJavaTypeValue.getValue().getName();
return findOrBindEntityBinding( referencedEntityName ); return findOrBindEntityBinding( referencedEntityName );
} }

View File

@ -73,6 +73,7 @@ public abstract class AbstractEntitySourceImpl
private final EntityElement entityElement; private final EntityElement entityElement;
private final String className; private final String className;
private final String entityName; private final String entityName;
private final String jpaEntityName;
private List<SubclassEntitySource> subclassEntitySources = new ArrayList<SubclassEntitySource>(); private List<SubclassEntitySource> subclassEntitySources = new ArrayList<SubclassEntitySource>();
@ -87,9 +88,14 @@ public abstract class AbstractEntitySourceImpl
this.entityElement = entityElement; this.entityElement = entityElement;
this.className = bindingContext().qualifyClassName( entityElement.getName() ); this.className = bindingContext().qualifyClassName( entityElement.getName() );
this.entityName = StringHelper.isNotEmpty( entityElement.getEntityName() ) if ( StringHelper.isNotEmpty( entityElement.getEntityName() ) ) {
? entityElement.getEntityName() this.entityName = entityElement.getEntityName();
: className; this.jpaEntityName = entityElement.getEntityName();
}
else {
this.entityName = className;
this.jpaEntityName = StringHelper.unqualify( className );
}
} }
@Override @Override
@ -375,7 +381,7 @@ public abstract class AbstractEntitySourceImpl
@Override @Override
public String getJpaEntityName() { public String getJpaEntityName() {
return null; return jpaEntityName;
} }
@Override @Override

View File

@ -164,7 +164,7 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
@Override @Override
public String getReferencedEntityName() { public String getReferencedEntityName() {
return manyToOneElement.getClazz() != null return manyToOneElement.getClazz() != null
? manyToOneElement.getClazz() ? bindingContext().qualifyClassName( manyToOneElement.getClazz() )
: manyToOneElement.getEntityName(); : manyToOneElement.getEntityName();
} }

View File

@ -171,7 +171,7 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
@Override @Override
public String getReferencedEntityName() { public String getReferencedEntityName() {
return oneToOneElement.getClazz() != null return oneToOneElement.getClazz() != null
? oneToOneElement.getClazz() ? bindingContext().qualifyClassName( oneToOneElement.getClazz() )
: oneToOneElement.getEntityName(); : oneToOneElement.getEntityName();
} }

View File

@ -294,6 +294,7 @@ public class EntityIdentifier {
} }
params.setProperty( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() ); 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 //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 //TODO: would it be better to simply pass the qualified table name, instead of

View File

@ -25,9 +25,10 @@ package org.hibernate.metamodel.spi.relational;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
/** /**
@ -41,7 +42,7 @@ import org.hibernate.dialect.Dialect;
public abstract class AbstractConstraint implements Constraint { public abstract class AbstractConstraint implements Constraint {
private final TableSpecification table; private final TableSpecification table;
private String name; private String name;
private List<Column> columns = new ArrayList<Column>(); private final Map<Identifier, Column> columnMap = new LinkedHashMap<Identifier, Column>();
protected AbstractConstraint(TableSpecification table, String name) { protected AbstractConstraint(TableSpecification table, String name) {
this.table = table; this.table = table;
@ -108,19 +109,19 @@ public abstract class AbstractConstraint implements Constraint {
} }
protected int generateConstraintColumnListId() { protected int generateConstraintColumnListId() {
return table.generateColumnListId( columns ); return table.generateColumnListId( getColumns() );
} }
public List<Column> getColumns() { public List<Column> getColumns() {
return Collections.unmodifiableList( columns ); return Collections.unmodifiableList( new ArrayList<Column>( columnMap.values() ) );
} }
public int getColumnSpan() { public int getColumnSpan() {
return columns.size(); return columnMap.size();
} }
protected List<Column> internalColumnAccess() { protected Map<Identifier, Column> internalColumnAccess() {
return columns; return columnMap;
} }
public void addColumn(Column column) { 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) { protected boolean isCreationVetoed(Dialect dialect) {

View File

@ -95,12 +95,7 @@ public class AssertSourcesTest extends BaseUnitTestCase {
assertEquals( User.class.getName(), entitySource.getClassName() ); assertEquals( User.class.getName(), entitySource.getClassName() );
assertEquals( User.class.getName(), entitySource.getEntityName() ); assertEquals( User.class.getName(), entitySource.getEntityName() );
if ( HbmMetadataSourceProcessorImpl.class.isInstance( processor ) ) { assertEquals( StringHelper.unqualify( User.class.getName() ), entitySource.getJpaEntityName() );
assertNull( entitySource.getJpaEntityName() );
}
else {
assertEquals( StringHelper.unqualify( User.class.getName() ), entitySource.getJpaEntityName() );
}
assertEquals( EntityMode.POJO, entitySource.getEntityMode() ); assertEquals( EntityMode.POJO, entitySource.getEntityMode() );
assertNull( entitySource.getCaching() ); assertNull( entitySource.getCaching() );

View File

@ -33,7 +33,6 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.id.enhanced.TableGenerator;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -133,7 +132,6 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
@Test @Test
@TestForIssue(jiraKey = "HHH-6790") @TestForIssue(jiraKey = "HHH-6790")
@FailureExpectedWithNewMetamodel
public void testSequencePerEntity() { public void testSequencePerEntity() {
// Checking first entity. // Checking first entity.
EntityPersister persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() );

View File

@ -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.annotations.id.sequences.entities.Tree;
import org.hibernate.test.util.SchemaUtil; import org.hibernate.test.util.SchemaUtil;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -298,7 +297,6 @@ public class IdTest extends BaseCoreFunctionalTestCase {
@Test @Test
@TestForIssue(jiraKey = "HHH-6790") @TestForIssue(jiraKey = "HHH-6790")
@FailureExpectedWithNewMetamodel
public void testSequencePerEntity() { public void testSequencePerEntity() {
Session session = openSession(); Session session = openSession();
session.beginTransaction(); session.beginTransaction();

View File

@ -33,7 +33,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel;
* *
* @author Gail Badner * @author Gail Badner
*/ */
//@FailureExpectedWithNewMetamodel
public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest { public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -36,7 +36,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
//@FailureExpectedWithNewMetamodel
public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest { public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -40,7 +40,6 @@ import static org.junit.Assert.assertEquals;
* @author Steve Ebersole * @author Steve Ebersole
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@FailureExpectedWithNewMetamodel
public class BasicSequenceTest extends BaseCoreFunctionalTestCase { public class BasicSequenceTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -32,7 +32,6 @@ import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException; import org.hibernate.StaleStateException;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -48,7 +47,6 @@ import static org.junit.Assert.fail;
value = DialectChecks.DoesRepeatableReadNotCauseReadersToBlockWritersCheck.class, value = DialectChecks.DoesRepeatableReadNotCauseReadersToBlockWritersCheck.class,
comment = "potential deadlock" comment = "potential deadlock"
) )
@FailureExpectedWithNewMetamodel
public class OptimisticLockTest extends BaseCoreFunctionalTestCase { public class OptimisticLockTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -41,7 +41,6 @@ import static org.junit.Assert.assertTrue;
/** /**
* @author Gavin King * @author Gavin King
*/ */
@FailureExpectedWithNewMetamodel
public class TypedManyToOneTest extends BaseCoreFunctionalTestCase { public class TypedManyToOneTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {
@ -49,6 +48,7 @@ public class TypedManyToOneTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testCreateQuery() { public void testCreateQuery() {
Customer cust = new Customer(); Customer cust = new Customer();
cust.setCustomerId("abc123"); cust.setCustomerId("abc123");

View File

@ -30,7 +30,6 @@ import org.junit.Test;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -40,7 +39,6 @@ import static org.junit.Assert.assertTrue;
/** /**
* @author Gavin King * @author Gavin King
*/ */
@FailureExpectedWithNewMetamodel
public class TypedOneToOneTest extends BaseCoreFunctionalTestCase { public class TypedOneToOneTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {