Skip to content

Commit 377ba9a

Browse files
committed
HHH-10322 : Test failures due to function name differences by dialect
1 parent cd581f8 commit 377ba9a

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

hibernate-core/src/test/java/org/hibernate/test/subselectfetch/SubselectFetchWithFormulaTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
import java.util.List;
1010

1111
import org.hibernate.Session;
12+
import org.hibernate.dialect.SQLServerDialect;
13+
import org.hibernate.dialect.SybaseDialect;
1214
import org.hibernate.mapping.Collection;
1315

16+
import org.hibernate.testing.SkipForDialect;
1417
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
1518
import org.junit.After;
1619
import org.junit.Before;
@@ -19,6 +22,7 @@
1922
import static org.hamcrest.CoreMatchers.is;
2023
import static org.junit.Assert.assertThat;
2124

25+
@SkipForDialect({SQLServerDialect.class, SybaseDialect.class})
2226
public class SubselectFetchWithFormulaTest extends BaseNonConfigCoreFunctionalTestCase {
2327
@Override
2428
protected String getBaseForMappings() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.subselectfetch;
8+
9+
import java.util.List;
10+
11+
import org.junit.After;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
15+
import org.hibernate.Session;
16+
import org.hibernate.dialect.SQLServerDialect;
17+
import org.hibernate.dialect.SybaseDialect;
18+
import org.hibernate.mapping.Collection;
19+
import org.hibernate.testing.RequiresDialect;
20+
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
21+
22+
import static org.hamcrest.CoreMatchers.is;
23+
import static org.junit.Assert.assertThat;
24+
25+
@RequiresDialect({SQLServerDialect.class,SybaseDialect.class})
26+
public class SubselectFetchWithFormulaTransactSqlTest extends BaseNonConfigCoreFunctionalTestCase {
27+
@Override
28+
protected String getBaseForMappings() {
29+
return "";
30+
}
31+
32+
@Override
33+
protected String[] getMappings() {
34+
return new String[] {
35+
"org/hibernate/test/subselectfetch/NameTransactSql.hbm.xml",
36+
"org/hibernate/test/subselectfetch/Value.hbm.xml"
37+
};
38+
}
39+
40+
@Before
41+
public void before() {
42+
Session session = openSession();
43+
session.getTransaction().begin();
44+
45+
Name chris = new Name();
46+
chris.setId( 1 );
47+
chris.setName( "chris" );
48+
Value cat = new Value();
49+
cat.setId(1);
50+
cat.setName( chris );
51+
cat.setValue( "cat" );
52+
Value canary = new Value();
53+
canary.setId( 2 );
54+
canary.setName( chris );
55+
canary.setValue( "canary" );
56+
57+
session.persist( chris );
58+
session.persist( cat );
59+
session.persist( canary );
60+
61+
Name sam = new Name();
62+
sam.setId(2);
63+
sam.setName( "sam" );
64+
Value seal = new Value();
65+
seal.setId( 3 );
66+
seal.setName( sam );
67+
seal.setValue( "seal" );
68+
Value snake = new Value();
69+
snake.setId( 4 );
70+
snake.setName( sam );
71+
snake.setValue( "snake" );
72+
73+
session.persist( sam );
74+
session.persist(seal);
75+
session.persist( snake );
76+
77+
session.getTransaction().commit();
78+
session.close();
79+
}
80+
81+
@After
82+
public void after() {
83+
Session session = openSession();
84+
session.getTransaction().begin();
85+
session.createQuery( "delete Value" ).executeUpdate();
86+
session.createQuery( "delete Name" ).executeUpdate();
87+
session.getTransaction().commit();
88+
session.close();
89+
}
90+
91+
92+
@Test
93+
public void checkSubselectWithFormula() throws Exception {
94+
// as a pre-condition make sure that subselect fetching is enabled for the collection...
95+
Collection collectionBinding = metadata().getCollectionBinding( Name.class.getName() + ".values" );
96+
assertThat( collectionBinding.isSubselectLoadable(), is( true ) );
97+
98+
// Now force the subselect fetch and make sure we do not get SQL errors
99+
Session session = openSession();
100+
session.getTransaction().begin();
101+
List results = session.createCriteria(Name.class).list();
102+
for (Object result : results) {
103+
Name name = (Name) result;
104+
name.getValues().size();
105+
}
106+
session.getTransaction().commit();
107+
session.close();
108+
}
109+
110+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Hibernate, Relational Persistence for Idiomatic Java
4+
~
5+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
-->
8+
<!DOCTYPE hibernate-mapping
9+
PUBLIC "-//Hibernate?Hibernate Mapping DTD//EN"
10+
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
11+
12+
<hibernate-mapping>
13+
14+
<class name="org.hibernate.test.subselectfetch.Name" table="Name">
15+
<id name="id" column="id"/>
16+
<property name="name" column="name"/>
17+
18+
<property name="nameLength" formula="(select len(name) from name where id=name.id)"/>
19+
20+
<bag name="values" inverse="true" lazy="false" fetch="subselect">
21+
<key column="name_id"/>
22+
<one-to-many class="org.hibernate.test.subselectfetch.Value"/>
23+
</bag>
24+
25+
</class>
26+
27+
</hibernate-mapping>

0 commit comments

Comments
 (0)