Skip to content

Commit

Permalink
HHH-10608 - Avoid exception from Hibernate.initialize when lazy_no_tr…
Browse files Browse the repository at this point in the history
…ansaction is enabled
  • Loading branch information
janario authored and vladmihalcea committed Mar 14, 2016
1 parent c681e48 commit d793051
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,7 @@ public final void forceInitialization() throws HibernateException {
if ( initializing ) {
throw new AssertionFailure( "force initialize loading collection" );
}
if ( session == null ) {
throw new HibernateException( "collection is not associated with any session" );
}
if ( !session.isConnected() ) {
throw new HibernateException( "disconnected session" );
}
session.initializeCollection( this, false );
initialize( false );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
Expand Down Expand Up @@ -53,6 +54,21 @@ protected void addSettings(Map settings) {
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
public void testOneToMany() {
Customer customer = new Customer();
Expand Down

0 comments on commit d793051

Please sign in to comment.