HHH-9864 HHH-11357 : Fixes required to backport; improvement to tests
This commit is contained in:
parent
9500f92bc6
commit
e791f77122
|
@ -1016,9 +1016,9 @@ public class ActionQueue {
|
||||||
|
|
||||||
private final String entityName;
|
private final String entityName;
|
||||||
|
|
||||||
private Set<String> parentEntityNames = new HashSet<>( );
|
private Set<String> parentEntityNames = new HashSet<String>( );
|
||||||
|
|
||||||
private Set<String> childEntityNames = new HashSet<>( );
|
private Set<String> childEntityNames = new HashSet<String>( );
|
||||||
|
|
||||||
public BatchIdentifier(
|
public BatchIdentifier(
|
||||||
String entityName) {
|
String entityName) {
|
||||||
|
@ -1034,12 +1034,12 @@ public class ActionQueue {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BatchIdentifier that = (BatchIdentifier) o;
|
BatchIdentifier that = (BatchIdentifier) o;
|
||||||
return Objects.equals( entityName, that.entityName );
|
return entityName.equals( that.entityName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash( entityName );
|
return entityName.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEntityName() {
|
public String getEntityName() {
|
||||||
|
@ -1071,9 +1071,9 @@ public class ActionQueue {
|
||||||
*/
|
*/
|
||||||
public void sort(List<AbstractEntityInsertAction> insertions) {
|
public void sort(List<AbstractEntityInsertAction> insertions) {
|
||||||
// optimize the hash size to eliminate a rehash.
|
// optimize the hash size to eliminate a rehash.
|
||||||
this.latestBatches = new ArrayList<>( );
|
this.latestBatches = new ArrayList<BatchIdentifier>( );
|
||||||
this.entityBatchIdentifier = new HashMap<>( insertions.size() + 1, 1.0f );
|
this.entityBatchIdentifier = new HashMap<Object, BatchIdentifier>( insertions.size() + 1, 1.0f );
|
||||||
this.actionBatches = new HashMap<>();
|
this.actionBatches = new HashMap<BatchIdentifier, List<AbstractEntityInsertAction>>();
|
||||||
|
|
||||||
for ( AbstractEntityInsertAction action : insertions ) {
|
for ( AbstractEntityInsertAction action : insertions ) {
|
||||||
BatchIdentifier batchIdentifier = new BatchIdentifier( action.getEntityName() );
|
BatchIdentifier batchIdentifier = new BatchIdentifier( action.getEntityName() );
|
||||||
|
@ -1156,7 +1156,7 @@ public class ActionQueue {
|
||||||
List<AbstractEntityInsertAction> actions = actionBatches.get( batchIdentifier );
|
List<AbstractEntityInsertAction> actions = actionBatches.get( batchIdentifier );
|
||||||
|
|
||||||
if ( actions == null ) {
|
if ( actions == null ) {
|
||||||
actions = new LinkedList<>();
|
actions = new LinkedList<AbstractEntityInsertAction>();
|
||||||
actionBatches.put( batchIdentifier, actions );
|
actionBatches.put( batchIdentifier, actions );
|
||||||
}
|
}
|
||||||
actions.add( action );
|
actions.add( action );
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.insertordering;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
class InsertOrderingStatementInspector implements StatementInspector {
|
||||||
|
private Map<String, Integer> countBySqlStrings = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String inspect(String sql) {
|
||||||
|
Integer count = countBySqlStrings.get( sql );
|
||||||
|
if ( count == null ) {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
countBySqlStrings.put( sql, count + 1 );
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getCount(String sql) {
|
||||||
|
Integer count = countBySqlStrings.get( sql );
|
||||||
|
return count == null ? 0 : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
countBySqlStrings.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Integer> getCountBySqlStrings() {
|
||||||
|
return Collections.unmodifiableMap( countBySqlStrings );
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.insertordering;
|
package org.hibernate.test.insertordering;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,17 +19,14 @@ import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
|
@ -38,8 +34,7 @@ import static org.mockito.Mockito.verify;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithBidirectionalManyToMany
|
public class InsertOrderingWithBidirectionalManyToMany
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -50,21 +45,18 @@ public class InsertOrderingWithBidirectionalManyToMany
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatching() throws SQLException {
|
public void testBatching() throws SQLException {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
Person father = new Person();
|
Person father = new Person();
|
||||||
Person mother = new Person();
|
Person mother = new Person();
|
||||||
Person son = new Person();
|
Person son = new Person();
|
||||||
|
@ -84,16 +76,14 @@ public class InsertOrderingWithBidirectionalManyToMany
|
||||||
session.persist( home );
|
session.persist( home );
|
||||||
session.persist( office );
|
session.persist( office );
|
||||||
|
|
||||||
connectionProvider.clear();
|
session.getTransaction().commit();
|
||||||
} );
|
session.close();
|
||||||
|
|
||||||
assertEquals( 3, connectionProvider.getPreparedStatements().size() );
|
assertEquals( 1, statementInspector.getCount( "insert into Address (ID) values (?)" ) );
|
||||||
PreparedStatement addressPreparedStatement = connectionProvider.getPreparedStatement(
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount() );
|
||||||
"insert into Address (ID) values (?)" );
|
|
||||||
verify( addressPreparedStatement, times( 2 ) ).addBatch();
|
assertEquals( 1, statementInspector.getCount( "insert into Person (ID) values (?)" ) );
|
||||||
PreparedStatement personPreparedStatement = connectionProvider.getPreparedStatement(
|
assertEquals( 4, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
"insert into Person (ID) values (?)" );
|
|
||||||
verify( personPreparedStatement, times( 4 ) ).addBatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "Address")
|
@Entity(name = "Address")
|
||||||
|
@ -105,7 +95,7 @@ public class InsertOrderingWithBidirectionalManyToMany
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "addresses", cascade = CascadeType.PERSIST)
|
@ManyToMany(mappedBy = "addresses", cascade = CascadeType.PERSIST)
|
||||||
private List<Person> persons = new ArrayList<>();
|
private List<Person> persons = new ArrayList<Person>();
|
||||||
|
|
||||||
public void addPerson(Person person) {
|
public void addPerson(Person person) {
|
||||||
persons.add( person );
|
persons.add( person );
|
||||||
|
@ -122,6 +112,6 @@ public class InsertOrderingWithBidirectionalManyToMany
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
private List<Address> addresses = new ArrayList<>();
|
private List<Address> addresses = new ArrayList<Address>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.insertordering;
|
package org.hibernate.test.insertordering;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -21,16 +20,14 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
|
@ -38,8 +35,7 @@ import static org.mockito.Mockito.verify;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithBidirectionalOneToMany
|
public class InsertOrderingWithBidirectionalOneToMany
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -50,21 +46,18 @@ public class InsertOrderingWithBidirectionalOneToMany
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatching() throws SQLException {
|
public void testBatching() throws SQLException {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
Person father = new Person();
|
Person father = new Person();
|
||||||
Person mother = new Person();
|
Person mother = new Person();
|
||||||
Person son = new Person();
|
Person son = new Person();
|
||||||
|
@ -84,15 +77,14 @@ public class InsertOrderingWithBidirectionalOneToMany
|
||||||
session.persist( home );
|
session.persist( home );
|
||||||
session.persist( office );
|
session.persist( office );
|
||||||
|
|
||||||
connectionProvider.clear();
|
session.getTransaction().commit();
|
||||||
} );
|
session.close();
|
||||||
|
|
||||||
PreparedStatement addressPreparedStatement = connectionProvider.getPreparedStatement(
|
assertEquals( 1, statementInspector.getCount( "insert into Address (ID) values (?)" ) );
|
||||||
"insert into Address (ID) values (?)" );
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount() );
|
||||||
verify( addressPreparedStatement, times( 2 ) ).addBatch();
|
|
||||||
PreparedStatement personPreparedStatement = connectionProvider.getPreparedStatement(
|
assertEquals( 1, statementInspector.getCount( "insert into Person (address_ID, ID) values (?, ?)" ) );
|
||||||
"insert into Person (address_ID, ID) values (?, ?)" );
|
assertEquals( 4, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
verify( personPreparedStatement, times( 4 ) ).addBatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "Address")
|
@Entity(name = "Address")
|
||||||
|
@ -104,7 +96,7 @@ public class InsertOrderingWithBidirectionalOneToMany
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "address", cascade = CascadeType.PERSIST)
|
@OneToMany(mappedBy = "address", cascade = CascadeType.PERSIST)
|
||||||
private List<Person> persons = new ArrayList<>();
|
private List<Person> persons = new ArrayList<Person>();
|
||||||
|
|
||||||
public void addPerson(Person person) {
|
public void addPerson(Person person) {
|
||||||
persons.add( person );
|
persons.add( person );
|
||||||
|
|
|
@ -27,15 +27,14 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.BatchSize;
|
import org.hibernate.annotations.BatchSize;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,8 +43,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithJoinedTableInheritance
|
public class InsertOrderingWithJoinedTableInheritance
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -56,21 +54,15 @@ public class InsertOrderingWithJoinedTableInheritance
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchOrdering() {
|
public void testBatchOrdering() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
person.addAddress( new Address() );
|
person.addAddress( new Address() );
|
||||||
session.persist( person );
|
session.persist( person );
|
||||||
|
@ -79,12 +71,19 @@ public class InsertOrderingWithJoinedTableInheritance
|
||||||
final SpecialPerson specialPerson = new SpecialPerson();
|
final SpecialPerson specialPerson = new SpecialPerson();
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
} );
|
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchingAmongstSubClasses() {
|
public void testBatchingAmongstSubClasses() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
int iterations = 12;
|
int iterations = 12;
|
||||||
for ( int i = 0; i < iterations; i++ ) {
|
for ( int i = 0; i < iterations; i++ ) {
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
|
@ -95,10 +94,22 @@ public class InsertOrderingWithJoinedTableInheritance
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
}
|
}
|
||||||
connectionProvider.clear();
|
|
||||||
} );
|
|
||||||
|
|
||||||
assertEquals( 26, connectionProvider.getPreparedStatements().size() );
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into ADDRESS (PERSONID, ID) values (?, ?)" ) );
|
||||||
|
assertEquals(
|
||||||
|
24,
|
||||||
|
sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount()
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (1, ?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 12, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (2, ?)" ) );
|
||||||
|
assertEquals( 12, statementInspector.getCount( "insert into SpecialPerson (special, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( SpecialPerson.class.getName() ).getInsertCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,6 +14,7 @@ import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.DiscriminatorColumn;
|
import javax.persistence.DiscriminatorColumn;
|
||||||
import javax.persistence.DiscriminatorType;
|
import javax.persistence.DiscriminatorType;
|
||||||
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
|
@ -26,15 +27,14 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.BatchSize;
|
import org.hibernate.annotations.BatchSize;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,8 +43,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -62,21 +61,18 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchingAmongstSubClasses() {
|
public void testBatchingAmongstSubClasses() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
int iterations = 2;
|
int iterations = 2;
|
||||||
for ( int i = 0; i < iterations; i++ ) {
|
for ( int i = 0; i < iterations; i++ ) {
|
||||||
final President president = new President();
|
final President president = new President();
|
||||||
|
@ -96,10 +92,33 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
}
|
}
|
||||||
connectionProvider.clear();
|
|
||||||
} );
|
|
||||||
|
|
||||||
assertEquals( 17, connectionProvider.getPreparedStatements().size() );
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into ADDRESS (PERSONID, ID) values (?, ?)" ) );
|
||||||
|
assertEquals(
|
||||||
|
4,
|
||||||
|
sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount()
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into Office (ID) values (?)" ) );
|
||||||
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( Office.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (1, ?)" ) );
|
||||||
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 2, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (2, ?)" ) );
|
||||||
|
assertEquals( 4, statementInspector.getCount( "insert into SpecialPerson (special, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( SpecialPerson.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 2, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (3, ?)" ) );
|
||||||
|
assertEquals( 2, statementInspector.getCount( "insert into AnotherPerson (office_ID, working, ID) values (?, ?, ?)" ) );
|
||||||
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( AnotherPerson.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 2, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (4, ?)" ) );
|
||||||
|
assertEquals( 2, statementInspector.getCount( "insert into President (salary, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 2, sessionFactory().getStatistics().getEntityStatistics( President.class.getName() ).getInsertCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,14 +128,18 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void cleanupTestData() throws Exception {
|
protected void cleanupTestData() throws Exception {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
session.createQuery( "delete Address" ).executeUpdate();
|
session.createQuery( "delete Address" ).executeUpdate();
|
||||||
session.createQuery( "delete Person" ).executeUpdate();
|
session.createQuery( "delete Person" ).executeUpdate();
|
||||||
session.createQuery( "delete SpecialPerson" ).executeUpdate();
|
session.createQuery( "delete SpecialPerson" ).executeUpdate();
|
||||||
session.createQuery( "delete AnotherPerson" ).executeUpdate();
|
session.createQuery( "delete AnotherPerson" ).executeUpdate();
|
||||||
session.createQuery( "delete Office" ).executeUpdate();
|
session.createQuery( "delete Office" ).executeUpdate();
|
||||||
session.createQuery( "delete President" ).executeUpdate();
|
session.createQuery( "delete President" ).executeUpdate();
|
||||||
} );
|
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "Address")
|
@Entity(name = "Address")
|
||||||
|
@ -142,6 +165,7 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
@Table(name = "PERSON")
|
@Table(name = "PERSON")
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
@DiscriminatorColumn(name = "CLASSINDICATOR", discriminatorType = DiscriminatorType.INTEGER)
|
@DiscriminatorColumn(name = "CLASSINDICATOR", discriminatorType = DiscriminatorType.INTEGER)
|
||||||
|
@DiscriminatorValue("1")
|
||||||
public static class Person {
|
public static class Person {
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "ID", nullable = false)
|
@Column(name = "ID", nullable = false)
|
||||||
|
@ -152,6 +176,7 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "SpecialPerson")
|
@Entity(name = "SpecialPerson")
|
||||||
|
@DiscriminatorValue("2")
|
||||||
public static class SpecialPerson extends Person {
|
public static class SpecialPerson extends Person {
|
||||||
@Column(name = "special")
|
@Column(name = "special")
|
||||||
private String special;
|
private String special;
|
||||||
|
@ -170,6 +195,7 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "AnotherPerson")
|
@Entity(name = "AnotherPerson")
|
||||||
|
@DiscriminatorValue("3")
|
||||||
public static class AnotherPerson extends Person {
|
public static class AnotherPerson extends Person {
|
||||||
private boolean working;
|
private boolean working;
|
||||||
|
|
||||||
|
@ -178,6 +204,7 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "President")
|
@Entity(name = "President")
|
||||||
|
@DiscriminatorValue("4")
|
||||||
public static class President extends SpecialPerson {
|
public static class President extends SpecialPerson {
|
||||||
|
|
||||||
@Column(name = "salary")
|
@Column(name = "salary")
|
||||||
|
|
|
@ -27,15 +27,14 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.BatchSize;
|
import org.hibernate.annotations.BatchSize;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,8 +43,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithSingleTableInheritance
|
public class InsertOrderingWithSingleTableInheritance
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -56,21 +54,15 @@ public class InsertOrderingWithSingleTableInheritance
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchOrdering() {
|
public void testBatchOrdering() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
// First object with dependent object (address)
|
// First object with dependent object (address)
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
person.addAddress( new Address() );
|
person.addAddress( new Address() );
|
||||||
|
@ -80,12 +72,19 @@ public class InsertOrderingWithSingleTableInheritance
|
||||||
final SpecialPerson specialPerson = new SpecialPerson();
|
final SpecialPerson specialPerson = new SpecialPerson();
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
} );
|
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchingAmongstSubClasses() {
|
public void testBatchingAmongstSubClasses() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
int iterations = 12;
|
int iterations = 12;
|
||||||
for ( int i = 0; i < iterations; i++ ) {
|
for ( int i = 0; i < iterations; i++ ) {
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
|
@ -96,10 +95,18 @@ public class InsertOrderingWithSingleTableInheritance
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
}
|
}
|
||||||
connectionProvider.clear();
|
|
||||||
} );
|
|
||||||
|
|
||||||
assertEquals( 3, connectionProvider.getPreparedStatements().size() );
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into ADDRESS (PERSONID, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 24, sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into PERSON (CLASSINDICATOR, ID) values (1, ?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into PERSON (special, CLASSINDICATOR, ID) values (?, 2, ?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( SpecialPerson.class.getName() ).getInsertCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,15 +27,14 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.BatchSize;
|
import org.hibernate.annotations.BatchSize;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,8 +43,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
@TestForIssue(jiraKey = "HHH-9864")
|
@TestForIssue(jiraKey = "HHH-9864")
|
||||||
public class InsertOrderingWithTablePerClassInheritance
|
public class InsertOrderingWithTablePerClassInheritance
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
private InsertOrderingStatementInspector statementInspector = new InsertOrderingStatementInspector();
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -56,21 +54,15 @@ public class InsertOrderingWithTablePerClassInheritance
|
||||||
protected void addSettings(Map settings) {
|
protected void addSettings(Map settings) {
|
||||||
settings.put( Environment.ORDER_INSERTS, "true" );
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" );
|
||||||
settings.put(
|
settings.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
|
settings.put( Environment.STATEMENT_INSPECTOR, statementInspector );
|
||||||
connectionProvider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseResources() {
|
|
||||||
super.releaseResources();
|
|
||||||
connectionProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchOrdering() {
|
public void testBatchOrdering() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
// First object with dependent object (address)
|
// First object with dependent object (address)
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
person.addAddress( new Address() );
|
person.addAddress( new Address() );
|
||||||
|
@ -80,12 +72,19 @@ public class InsertOrderingWithTablePerClassInheritance
|
||||||
final SpecialPerson specialPerson = new SpecialPerson();
|
final SpecialPerson specialPerson = new SpecialPerson();
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
} );
|
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchingAmongstSubClasses() {
|
public void testBatchingAmongstSubClasses() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
sessionFactory().getStatistics().clear();
|
||||||
|
statementInspector.clear();
|
||||||
|
|
||||||
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
int iterations = 12;
|
int iterations = 12;
|
||||||
for ( int i = 0; i < iterations; i++ ) {
|
for ( int i = 0; i < iterations; i++ ) {
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
|
@ -96,10 +95,18 @@ public class InsertOrderingWithTablePerClassInheritance
|
||||||
specialPerson.addAddress( new Address() );
|
specialPerson.addAddress( new Address() );
|
||||||
session.persist( specialPerson );
|
session.persist( specialPerson );
|
||||||
}
|
}
|
||||||
connectionProvider.clear();
|
|
||||||
} );
|
|
||||||
|
|
||||||
assertEquals( 3, connectionProvider.getPreparedStatements().size() );
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into ADDRESS (PERSONID, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 24, sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into PERSON (ID) values (?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( Person.class.getName() ).getInsertCount() );
|
||||||
|
|
||||||
|
assertEquals( 1, statementInspector.getCount( "insert into SpecialPerson (special, ID) values (?, ?)" ) );
|
||||||
|
assertEquals( 12, sessionFactory().getStatistics().getEntityStatistics( SpecialPerson.class.getName() ).getInsertCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue