HHH-951 - Add test for Criteria
This commit is contained in:
parent
0a722bb230
commit
2e7c3acf11
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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.criteria.limitexpression;
|
||||
|
||||
public class Country {
|
||||
private String code;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.criteria.limitexpression;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-915")
|
||||
@RequiresDialectFeature(
|
||||
value = DialectChecks.SupportLimitCheck.class,
|
||||
comment = "Dialect does not support limit"
|
||||
)
|
||||
public class LimitExpressionTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] {"criteria/limitexpression/domain.hbm.xml"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testWithFetchJoin() {
|
||||
Session session = openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
List<String> stateCodes = Arrays.asList( "DC", "CT" );
|
||||
Criteria crit = session.createCriteria( Person.class );
|
||||
crit.createCriteria( "states" ).add( Restrictions.in( "code", stateCodes ) );
|
||||
crit.setMaxResults( 10 );
|
||||
crit.list();
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
transaction.rollback();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.criteria.limitexpression;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class Person {
|
||||
private Long id;
|
||||
private Set<UsState> states;
|
||||
private Set<Country> countries;
|
||||
|
||||
public Set<UsState> getStates() {
|
||||
return states;
|
||||
}
|
||||
|
||||
public void setStates(Set<UsState> states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public Set<Country> getCountries() {
|
||||
return countries;
|
||||
}
|
||||
|
||||
public void setCountries(Set<Country> countries) {
|
||||
this.countries = countries;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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.criteria.limitexpression;
|
||||
|
||||
public class UsState {
|
||||
private String code;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.criteria.limitexpression">
|
||||
<class name="Person" table="person">
|
||||
<id column="id" type="long"/>
|
||||
|
||||
<set name="states" table="person_states" inverse="false" lazy="false" fetch="join">
|
||||
<key column="id_person" not-null="true"/>
|
||||
<many-to-many class="UsState" column="code_state"/>
|
||||
</set>
|
||||
|
||||
<set name="countries" table="person_countries" inverse="false" lazy="false" fetch="join">
|
||||
<key column="id_person" not-null="true"/>
|
||||
<many-to-many class="Country" column="code_country"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
<class name="UsState" table="us_state">
|
||||
<id column="code" name="code" type="string"/>
|
||||
</class>
|
||||
|
||||
<class name="Country" table="country">
|
||||
<id column="code" name="code" type="string"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue