HHH-10608 - Avoid exception from Hibernate.initialize when lazy_no_transaction is enabled
(cherry picked from commit 7232b7ccd5
)
This commit is contained in:
parent
bc917f1176
commit
337ee18b19
|
@ -736,13 +736,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
||||||
if ( initializing ) {
|
if ( initializing ) {
|
||||||
throw new AssertionFailure( "force initialize loading collection" );
|
throw new AssertionFailure( "force initialize loading collection" );
|
||||||
}
|
}
|
||||||
if ( session == null ) {
|
initialize( false );
|
||||||
throw new HibernateException( "collection is not associated with any session" );
|
|
||||||
}
|
|
||||||
if ( !session.isConnected() ) {
|
|
||||||
throw new HibernateException( "disconnected session" );
|
|
||||||
}
|
|
||||||
session.initializeCollection( this, false );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.Cache;
|
import org.hibernate.annotations.Cache;
|
||||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||||
|
@ -53,6 +54,21 @@ public class CacheLazyLoadNoTransTest extends BaseNonConfigCoreFunctionalTestCas
|
||||||
settings.put( Environment.CACHE_PROVIDER_CONFIG, "true" );
|
settings.put( Environment.CACHE_PROVIDER_CONFIG, "true" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hibernateInitialize() {
|
||||||
|
Customer customer = new Customer();
|
||||||
|
Item item1 = new Item( customer );
|
||||||
|
Item item2 = new Item( customer );
|
||||||
|
customer.boughtItems.add( item1 );
|
||||||
|
customer.boughtItems.add( item2 );
|
||||||
|
persist( customer );
|
||||||
|
|
||||||
|
customer = find( Customer.class, customer.id );
|
||||||
|
assertFalse( Hibernate.isInitialized( customer.boughtItems ) );
|
||||||
|
Hibernate.initialize( customer.boughtItems );
|
||||||
|
assertTrue( Hibernate.isInitialized( customer.boughtItems ) );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneToMany() {
|
public void testOneToMany() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
|
|
Loading…
Reference in New Issue