HHH-4991 ; ManyToMany table not joined due to max_fetch_depth parameter, results to SQL exceptions
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19312 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
3c2ecd8afa
commit
1c556dc775
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.test.annotations.manytomany;
|
||||
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
/**
|
||||
* Many to many tests using max_fetch_depth == 0
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ManyToManyMaxFetchDepth0Test extends ManyToManyTest {
|
||||
|
||||
public ManyToManyMaxFetchDepth0Test(String x) {
|
||||
super( x );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.MAX_FETCH_DEPTH, "0" );
|
||||
super.configure( cfg );
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
|
||||
/**
|
||||
|
@ -80,6 +81,29 @@ public class ManyToManyTest extends TestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
public void testCanUseCriteriaQuery() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Store fnac = new Store();
|
||||
fnac.setName( "Fnac" );
|
||||
Supplier emi = new Supplier();
|
||||
emi.setName( "Emmanuel" );
|
||||
emi.setSuppStores( new HashSet<Store>() );
|
||||
fnac.setSuppliers( new HashSet<Supplier>() );
|
||||
fnac.getSuppliers().add( emi );
|
||||
emi.getSuppStores().add( fnac );
|
||||
s.persist( fnac );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add(
|
||||
Restrictions.eq( "s.name", "Fnac" ) ).list();
|
||||
assertEquals( 1, result.size() );
|
||||
s.close();
|
||||
}
|
||||
public void testDefaultCompositePk() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
|
|
|
@ -473,7 +473,7 @@ public class JoinWalker {
|
|||
* {@link JoinFragment#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
|
||||
* @throws MappingException ??
|
||||
*/
|
||||
private int getJoinType(
|
||||
protected int getJoinType(
|
||||
AssociationType associationType,
|
||||
FetchMode config,
|
||||
String path,
|
||||
|
|
|
@ -170,7 +170,31 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int getJoinType(
|
||||
AssociationType associationType,
|
||||
FetchMode config,
|
||||
String path,
|
||||
String lhsTable,
|
||||
String[] lhsColumns,
|
||||
boolean nullable,
|
||||
int currentDepth,
|
||||
CascadeStyle cascadeStyle) throws MappingException {
|
||||
return ( translator.isJoin( path ) ?
|
||||
translator.getJoinType( path ) :
|
||||
super.getJoinType(
|
||||
associationType,
|
||||
config,
|
||||
path,
|
||||
lhsTable,
|
||||
lhsColumns,
|
||||
nullable,
|
||||
currentDepth,
|
||||
cascadeStyle
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean isDefaultFetchMode(FetchMode fetchMode) {
|
||||
return fetchMode==null || fetchMode==FetchMode.DEFAULT;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.dialect.MySQLDialect;
|
|||
import org.hibernate.engine.EntityEntry;
|
||||
import org.hibernate.impl.SessionImpl;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
|
||||
public class ParentChildTest extends LegacyTestCase {
|
||||
|
@ -207,7 +208,7 @@ public class ParentChildTest extends LegacyTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
public void testComplexCriteriaFailureExpected() throws Exception {
|
||||
public void testComplexCriteria() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
|
@ -338,6 +339,109 @@ public class ParentChildTest extends LegacyTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
public void testArrayHQL() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
s.save(baz);
|
||||
Foo foo1 = new Foo();
|
||||
s.save(foo1);
|
||||
baz.setFooArray( new FooProxy[] { foo1 } );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
baz = ( Baz ) s.createQuery("from Baz b left join fetch b.fooArray").uniqueResult();
|
||||
assertEquals( 1, baz.getFooArray().length );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
public void testArrayCriteria() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
s.save(baz);
|
||||
Foo foo1 = new Foo();
|
||||
s.save(foo1);
|
||||
baz.setFooArray( new FooProxy[] { foo1 } );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
baz = ( Baz ) s.createCriteria(Baz.class).createCriteria( "fooArray" ).uniqueResult();
|
||||
assertEquals( 1, baz.getFooArray().length );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testLazyManyToOneHQL() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
s.save(baz);
|
||||
Foo foo1 = new Foo();
|
||||
s.save(foo1);
|
||||
baz.setFoo( foo1 );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
baz = ( Baz ) s.createQuery("from Baz b").uniqueResult();
|
||||
assertFalse( Hibernate.isInitialized( baz.getFoo() ) );
|
||||
assertTrue( baz.getFoo() instanceof HibernateProxy );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
public void testLazyManyToOneCriteria() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
s.save(baz);
|
||||
Foo foo1 = new Foo();
|
||||
s.save(foo1);
|
||||
baz.setFoo( foo1 );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
baz = ( Baz ) s.createCriteria( Baz.class ).uniqueResult();
|
||||
assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
|
||||
assertFalse( baz.getFoo() instanceof HibernateProxy );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testLazyManyToOneGet() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Baz baz = new Baz();
|
||||
s.save(baz);
|
||||
Foo foo1 = new Foo();
|
||||
s.save(foo1);
|
||||
baz.setFoo( foo1 );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
baz = ( Baz ) s.get( Baz.class, baz.getCode() );
|
||||
assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
|
||||
assertFalse( baz.getFoo() instanceof HibernateProxy );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testClassWhere() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
|
Loading…
Reference in New Issue