HHH-7877 : Add support for multiple entity names used with the same Java class
This commit is contained in:
parent
0c6ab56372
commit
2bee7d5111
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SubclassEntitySource> subclassEntitySources = new ArrayList<SubclassEntitySource>();
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -164,7 +164,7 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
|||
@Override
|
||||
public String getReferencedEntityName() {
|
||||
return manyToOneElement.getClazz() != null
|
||||
? manyToOneElement.getClazz()
|
||||
? bindingContext().qualifyClassName( manyToOneElement.getClazz() )
|
||||
: manyToOneElement.getEntityName();
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
|||
@Override
|
||||
public String getReferencedEntityName() {
|
||||
return oneToOneElement.getClazz() != null
|
||||
? oneToOneElement.getClazz()
|
||||
? bindingContext().qualifyClassName( oneToOneElement.getClazz() )
|
||||
: oneToOneElement.getEntityName();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Column> columns = new ArrayList<Column>();
|
||||
private final Map<Identifier, Column> columnMap = new LinkedHashMap<Identifier, Column>();
|
||||
|
||||
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<Column> getColumns() {
|
||||
return Collections.unmodifiableList( columns );
|
||||
return Collections.unmodifiableList( new ArrayList<Column>( columnMap.values() ) );
|
||||
}
|
||||
|
||||
public int getColumnSpan() {
|
||||
return columns.size();
|
||||
return columnMap.size();
|
||||
}
|
||||
|
||||
protected List<Column> internalColumnAccess() {
|
||||
return columns;
|
||||
protected Map<Identifier, Column> 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) {
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
//@FailureExpectedWithNewMetamodel
|
||||
public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
//@FailureExpectedWithNewMetamodel
|
||||
public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue