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

View File

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

View File

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

View File

@ -8,6 +8,8 @@ package org.hibernate.orm.test.sql.exec.manytoone;
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.SimpleEntity;
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.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@ -32,24 +36,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
}
)
@ServiceRegistry
@SessionFactory
@SessionFactory(generateStatistics = true)
public class EntityWithManyToOneJoinTableTest {
// @AfterEach
// public void tearDown(SessionFactoryScope scope) {
// scope.inTransaction(
// session -> {
// final EntityWithManyToOneJoinTable loaded = session.get( EntityWithManyToOneJoinTable.class, 1 );
// session.delete( loaded );
// session.delete( loaded.getOther() );
// }
// );
// }
@Test
// @FailureExpected
public void testSave(SessionFactoryScope scope) {
EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable( 1, "first", Integer.MAX_VALUE );
@BeforeEach
public void setUp(SessionFactoryScope scope) {
EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable(
1,
"first",
Integer.MAX_VALUE
);
SimpleEntity other = new SimpleEntity(
2,
@ -63,8 +59,41 @@ public class EntityWithManyToOneJoinTableTest {
entity.setOther( other );
scope.inTransaction( session -> {
session.save( entity );
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 -> {
session.save( entity );
} );
@ -78,41 +107,53 @@ public class EntityWithManyToOneJoinTableTest {
assertThat( loaded.getOther().getId(), equalTo( 2 ) );
}
);
}
@Test
@FailureExpected
public void testHqlSelect(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction(
session -> {
final SimpleEntity loaded = session.get( SimpleEntity.class, 2 );
assert loaded != null;
assertThat( loaded.getSomeInteger(), equalTo( Integer.MAX_VALUE ) );
final EntityWithManyToOneJoinTable result = session.createQuery(
"select e from EntityWithManyToOneJoinTable e where e.id = 2",
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
@FailureExpected
public void testHqlSelect(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 );
} );
public void testHqlSelectWithJoin(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
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
).uniqueResult();
assertThat( value, equalTo( "first" ) );