Skip to content

Commit 2e7c3ac

Browse files
committed
HHH-951 - Add test for Criteria
1 parent 0a722bb commit 2e7c3ac

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.criteria.limitexpression;
8+
9+
public class Country {
10+
private String code;
11+
12+
public String getCode() {
13+
return code;
14+
}
15+
16+
public void setCode(String code) {
17+
this.code = code;
18+
}
19+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.criteria.limitexpression;
8+
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
import org.hibernate.Criteria;
13+
import org.hibernate.Session;
14+
import org.hibernate.Transaction;
15+
import org.hibernate.criterion.Restrictions;
16+
17+
import org.hibernate.testing.DialectChecks;
18+
import org.hibernate.testing.RequiresDialectFeature;
19+
import org.hibernate.testing.TestForIssue;
20+
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
21+
22+
import static junit.framework.TestCase.fail;
23+
24+
/**
25+
* @author Andrea Boriero
26+
*/
27+
@TestForIssue(jiraKey = "HHH-915")
28+
@RequiresDialectFeature(
29+
value = DialectChecks.SupportLimitCheck.class,
30+
comment = "Dialect does not support limit"
31+
)
32+
public class LimitExpressionTest extends BaseNonConfigCoreFunctionalTestCase {
33+
34+
@Override
35+
public String[] getMappings() {
36+
return new String[] {"criteria/limitexpression/domain.hbm.xml"};
37+
}
38+
39+
@Override
40+
public String getCacheConcurrencyStrategy() {
41+
return null;
42+
}
43+
44+
@org.junit.Test
45+
public void testWithFetchJoin() {
46+
Session session = openSession();
47+
Transaction transaction = session.beginTransaction();
48+
try {
49+
List<String> stateCodes = Arrays.asList( "DC", "CT" );
50+
Criteria crit = session.createCriteria( Person.class );
51+
crit.createCriteria( "states" ).add( Restrictions.in( "code", stateCodes ) );
52+
crit.setMaxResults( 10 );
53+
crit.list();
54+
55+
transaction.commit();
56+
}
57+
catch (Exception e) {
58+
transaction.rollback();
59+
fail(e.getMessage());
60+
}
61+
finally {
62+
session.close();
63+
}
64+
}
65+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.criteria.limitexpression;
8+
9+
import java.util.Set;
10+
11+
public class Person {
12+
private Long id;
13+
private Set<UsState> states;
14+
private Set<Country> countries;
15+
16+
public Set<UsState> getStates() {
17+
return states;
18+
}
19+
20+
public void setStates(Set<UsState> states) {
21+
this.states = states;
22+
}
23+
24+
public Set<Country> getCountries() {
25+
return countries;
26+
}
27+
28+
public void setCountries(Set<Country> countries) {
29+
this.countries = countries;
30+
}
31+
32+
public Long getId() {
33+
return id;
34+
}
35+
36+
public void setId(Long id) {
37+
this.id = id;
38+
}
39+
40+
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.criteria.limitexpression;
8+
9+
public class UsState {
10+
private String code;
11+
12+
public String getCode() {
13+
return code;
14+
}
15+
16+
public void setCode(String code) {
17+
this.code = code;
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
3+
4+
<hibernate-mapping package="org.hibernate.test.criteria.limitexpression">
5+
<class name="Person" table="person">
6+
<id column="id" type="long"/>
7+
8+
<set name="states" table="person_states" inverse="false" lazy="false" fetch="join">
9+
<key column="id_person" not-null="true"/>
10+
<many-to-many class="UsState" column="code_state"/>
11+
</set>
12+
13+
<set name="countries" table="person_countries" inverse="false" lazy="false" fetch="join">
14+
<key column="id_person" not-null="true"/>
15+
<many-to-many class="Country" column="code_country"/>
16+
</set>
17+
</class>
18+
19+
<class name="UsState" table="us_state">
20+
<id column="code" name="code" type="string"/>
21+
</class>
22+
23+
<class name="Country" table="country">
24+
<id column="code" name="code" type="string"/>
25+
</class>
26+
</hibernate-mapping>

0 commit comments

Comments
 (0)