diff --git a/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTest.java index 37174e95ab..ab50580099 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTest.java @@ -9,8 +9,11 @@ package org.hibernate.test.subselectfetch; import java.util.List; import org.hibernate.Session; +import org.hibernate.dialect.SQLServerDialect; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.mapping.Collection; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.After; import org.junit.Before; @@ -19,6 +22,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +@SkipForDialect({SQLServerDialect.class, SybaseDialect.class}) public class SubselectFetchWithFormulaTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected String getBaseForMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTransactSqlTest.java b/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTransactSqlTest.java new file mode 100644 index 0000000000..4962b7666c --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTransactSqlTest.java @@ -0,0 +1,110 @@ +/* + * 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 . + */ +package org.hibernate.test.subselectfetch; + +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.Session; +import org.hibernate.dialect.SQLServerDialect; +import org.hibernate.dialect.SybaseDialect; +import org.hibernate.mapping.Collection; +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RequiresDialect({SQLServerDialect.class,SybaseDialect.class}) +public class SubselectFetchWithFormulaTransactSqlTest extends BaseNonConfigCoreFunctionalTestCase { + @Override + protected String getBaseForMappings() { + return ""; + } + + @Override + protected String[] getMappings() { + return new String[] { + "org/hibernate/test/subselectfetch/NameTransactSql.hbm.xml", + "org/hibernate/test/subselectfetch/Value.hbm.xml" + }; + } + + @Before + public void before() { + Session session = openSession(); + session.getTransaction().begin(); + + Name chris = new Name(); + chris.setId( 1 ); + chris.setName( "chris" ); + Value cat = new Value(); + cat.setId(1); + cat.setName( chris ); + cat.setValue( "cat" ); + Value canary = new Value(); + canary.setId( 2 ); + canary.setName( chris ); + canary.setValue( "canary" ); + + session.persist( chris ); + session.persist( cat ); + session.persist( canary ); + + Name sam = new Name(); + sam.setId(2); + sam.setName( "sam" ); + Value seal = new Value(); + seal.setId( 3 ); + seal.setName( sam ); + seal.setValue( "seal" ); + Value snake = new Value(); + snake.setId( 4 ); + snake.setName( sam ); + snake.setValue( "snake" ); + + session.persist( sam ); + session.persist(seal); + session.persist( snake ); + + session.getTransaction().commit(); + session.close(); + } + + @After + public void after() { + Session session = openSession(); + session.getTransaction().begin(); + session.createQuery( "delete Value" ).executeUpdate(); + session.createQuery( "delete Name" ).executeUpdate(); + session.getTransaction().commit(); + session.close(); + } + + + @Test + public void checkSubselectWithFormula() throws Exception { + // as a pre-condition make sure that subselect fetching is enabled for the collection... + Collection collectionBinding = metadata().getCollectionBinding( Name.class.getName() + ".values" ); + assertThat( collectionBinding.isSubselectLoadable(), is( true ) ); + + // Now force the subselect fetch and make sure we do not get SQL errors + Session session = openSession(); + session.getTransaction().begin(); + List results = session.createCriteria(Name.class).list(); + for (Object result : results) { + Name name = (Name) result; + name.getValues().size(); + } + session.getTransaction().commit(); + session.close(); + } + +} diff --git a/hibernate-core/src/test/resources/org/hibernate/test/subselectfetch/NameTransactSql.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/subselectfetch/NameTransactSql.hbm.xml new file mode 100644 index 0000000000..38f1eb2cf0 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/subselectfetch/NameTransactSql.hbm.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + +