changed order of AbstractEntityPersister#attributeMappings

This commit is contained in:
Andrea Boriero 2019-11-15 12:27:36 +00:00 committed by Steve Ebersole
parent b986ef1ea8
commit 36bf9f9dfe
4 changed files with 82 additions and 50 deletions

View File

@ -131,8 +131,6 @@ class DatabaseSnapshotExecutor {
sessionFactory.getTypeConfiguration() sessionFactory.getTypeConfiguration()
); );
rootQuerySpec.getSelectClause().addSqlSelection( sqlSelection );
//noinspection unchecked //noinspection unchecked
domainResults.add( domainResults.add(
new BasicResult( new BasicResult(
@ -146,15 +144,12 @@ class DatabaseSnapshotExecutor {
entityDescriptor.visitStateArrayContributors( entityDescriptor.visitStateArrayContributors(
contributorMapping -> { contributorMapping -> {
final NavigablePath attrPath = rootPath.append( contributorMapping.getAttributeName() ); rootPath.append( contributorMapping.getAttributeName() );
contributorMapping.visitColumns( contributorMapping.visitColumns(
(columnExpression, containingTableExpression, jdbcMapping) -> { (columnExpression, containingTableExpression, jdbcMapping) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference( final TableReference tableReference = rootTableGroup.resolveTableReference(
containingTableExpression ); containingTableExpression );
final JdbcParameter jdbcParameter = new JdbcParameterImpl( jdbcMapping );
jdbcParameters.add( jdbcParameter );
final ColumnReference columnReference = (ColumnReference) state.getSqlExpressionResolver() final ColumnReference columnReference = (ColumnReference) state.getSqlExpressionResolver()
.resolveSqlExpression( .resolveSqlExpression(
SqlExpressionResolver.createColumnReferenceKey( SqlExpressionResolver.createColumnReferenceKey(
@ -176,8 +171,6 @@ class DatabaseSnapshotExecutor {
sessionFactory.getTypeConfiguration() sessionFactory.getTypeConfiguration()
); );
rootQuerySpec.getSelectClause().addSqlSelection( sqlSelection );
//noinspection unchecked //noinspection unchecked
domainResults.add( domainResults.add(
new BasicResult( new BasicResult(

View File

@ -6109,7 +6109,7 @@ public abstract class AbstractEntityPersister
private EntityVersionMapping versionMapping; private EntityVersionMapping versionMapping;
private EntityDiscriminatorMapping discriminatorMapping; private EntityDiscriminatorMapping discriminatorMapping;
private SortedMap<String, AttributeMapping> declaredAttributeMappings = new TreeMap<>(); private Map<String, AttributeMapping> declaredAttributeMappings = new LinkedHashMap<>();
private List<AttributeMapping> attributeMappings; private List<AttributeMapping> attributeMappings;
protected List<Fetchable> staticFetchableList; protected List<Fetchable> staticFetchableList;
@ -6222,7 +6222,6 @@ public abstract class AbstractEntityPersister
final RootClass entityBootDescriptor = (RootClass) creationProcess.getCreationContext() final RootClass entityBootDescriptor = (RootClass) creationProcess.getCreationContext()
.getBootModel() .getBootModel()
.getEntityBinding( entityMappingDescriptor.getRootEntityName() ); .getEntityBinding( entityMappingDescriptor.getRootEntityName() );
final Table rootTable = entityBootDescriptor.getRootTable();
return SqmMutationStrategyHelper.resolveStrategy( return SqmMutationStrategyHelper.resolveStrategy(
entityBootDescriptor, entityBootDescriptor,

View File

@ -73,7 +73,6 @@ public class HqlDeleteExecutionTests {
} }
@Test @Test
@FailureExpected( reason = "Saving of entities with secondary tables is broken atm" )
public void testSimpleMultiTableRestrictedDeleteResults(SessionFactoryScope scope) { public void testSimpleMultiTableRestrictedDeleteResults(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> { session -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.orm.test.sql.exec.manytoone;
import java.util.Calendar; import java.util.Calendar;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable; import org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable;
import org.hibernate.testing.orm.domain.gambit.SimpleEntity; import org.hibernate.testing.orm.domain.gambit.SimpleEntity;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
@ -16,9 +18,11 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
@ -32,24 +36,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
} }
) )
@ServiceRegistry @ServiceRegistry
@SessionFactory @SessionFactory(generateStatistics = true)
public class EntityWithManyToOneJoinTableTest { public class EntityWithManyToOneJoinTableTest {
// @AfterEach @BeforeEach
// public void tearDown(SessionFactoryScope scope) { public void setUp(SessionFactoryScope scope) {
// scope.inTransaction( EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable(
// session -> { 1,
// final EntityWithManyToOneJoinTable loaded = session.get( EntityWithManyToOneJoinTable.class, 1 ); "first",
// session.delete( loaded ); Integer.MAX_VALUE
// session.delete( loaded.getOther() ); );
// }
// );
// }
@Test
// @FailureExpected
public void testSave(SessionFactoryScope scope) {
EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable( 1, "first", Integer.MAX_VALUE );
SimpleEntity other = new SimpleEntity( SimpleEntity other = new SimpleEntity(
2, 2,
@ -63,8 +59,41 @@ public class EntityWithManyToOneJoinTableTest {
entity.setOther( other ); entity.setOther( other );
scope.inTransaction( session -> { scope.inTransaction( session -> {
session.save( entity );
session.save( other ); session.save( other );
} ); } );
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete from EntityWithManyToOneJoinTable" ).executeUpdate();
session.createQuery( "delete from SimpleEntity" ).executeUpdate();
}
);
}
@Test
@FailureExpected
public void testSaveInDifferentTransactions(SessionFactoryScope scope) {
EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable( 3, "second", Integer.MAX_VALUE );
SimpleEntity other = new SimpleEntity(
4,
Calendar.getInstance().getTime(),
Calendar.getInstance().toInstant(),
Integer.MAX_VALUE -1 ,
Long.MAX_VALUE,
null
);
entity.setOther( other );
scope.inTransaction( session -> {
session.save( other );
} );
scope.inTransaction( session -> { scope.inTransaction( session -> {
session.save( entity ); session.save( entity );
} ); } );
@ -78,41 +107,53 @@ public class EntityWithManyToOneJoinTableTest {
assertThat( loaded.getOther().getId(), equalTo( 2 ) ); assertThat( loaded.getOther().getId(), equalTo( 2 ) );
} }
); );
}
@Test
@FailureExpected
public void testHqlSelect(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction( scope.inTransaction(
session -> { session -> {
final SimpleEntity loaded = session.get( SimpleEntity.class, 2 ); final EntityWithManyToOneJoinTable result = session.createQuery(
assert loaded != null; "select e from EntityWithManyToOneJoinTable e where e.id = 2",
assertThat( loaded.getSomeInteger(), equalTo( Integer.MAX_VALUE ) ); EntityWithManyToOneJoinTable.class
).uniqueResult();
assertThat( result, notNullValue() );
assertThat( result.getId(), is( 2 ) );
assertThat( result.getName(), is( "first" ) );
assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
}
);
}
@Test
public void testHqlSelectAField(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction(
session -> {
final String value = session.createQuery(
"select e.name from EntityWithManyToOneJoinTable e where e.other.id = 2",
String.class
).uniqueResult();
assertThat( value, equalTo( "first" ) );
assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
} }
); );
} }
@Test @Test
@FailureExpected @FailureExpected
public void testHqlSelect(SessionFactoryScope scope) { public void testHqlSelectWithJoin(SessionFactoryScope scope) {
EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable( 1, "first", Integer.MAX_VALUE );
SimpleEntity other = new SimpleEntity(
2,
Calendar.getInstance().getTime(),
null,
Integer.MAX_VALUE,
Long.MAX_VALUE,
null
);
entity.setOther( other );
scope.inTransaction( session -> {
session.save( other );
session.save( entity );
} );
scope.inTransaction( scope.inTransaction(
session -> { session -> {
final String value = session.createQuery( final String value = session.createQuery(
"select e.name from EntityWithManyToOneJoinTable e where e.other.id = 2", "select from EntityWithManyToOneJoinTable e where e.id = 2",
String.class String.class
).uniqueResult(); ).uniqueResult();
assertThat( value, equalTo( "first" ) ); assertThat( value, equalTo( "first" ) );