HHH-10322 : Test failures due to function name differences by dialect

(cherry picked from commit 377ba9a8c0)
This commit is contained in:
Gail Badner 2015-11-23 17:17:42 -08:00
parent 27f04f155d
commit 38b8074c55
3 changed files with 141 additions and 0 deletions

View File

@ -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() {

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
~ 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>.
-->
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate?Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.hibernate.test.subselectfetch.Name" table="Name">
<id name="id" column="id"/>
<property name="name" column="name"/>
<property name="nameLength" formula="(select len(name) from name where id=name.id)"/>
<bag name="values" inverse="true" lazy="false" fetch="subselect">
<key column="name_id"/>
<one-to-many class="org.hibernate.test.subselectfetch.Value"/>
</bag>
</class>
</hibernate-mapping>