Skip to content

Commit

Permalink
HHH-8558 - Bytecode enhancer: fix classloading issues on testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
barreiro authored and sebersole committed Jul 6, 2015
1 parent d5ed3a8 commit 8053fa7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Expand Up @@ -35,7 +35,7 @@ public LazyAttributeLoader(SessionImplementor session, Set<String> lazyFields, S
}

protected final Object intercept(Object target, String fieldName, Object value) {
if ( lazyFields != null && lazyFields.contains( fieldName ) && initializedFields.contains( fieldName ) ) {
if ( lazyFields != null && lazyFields.contains( fieldName ) && !initializedFields.contains( fieldName ) ) {
if ( session == null ) {
throw new LazyInitializationException( "entity with lazy properties is not associated with a session" );
}
Expand Down
Expand Up @@ -7,6 +7,9 @@
package org.hibernate.test.bytecode.enhancement;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
Expand All @@ -21,18 +24,20 @@ public abstract class AbstractEnhancerTestTask implements EnhancerTestTask {
private ServiceRegistry serviceRegistry;
private SessionFactory factory;

public final void prepare(Configuration user) {
Configuration cfg = new Configuration();
cfg.setProperties( user.getProperties() );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
public final void prepare(Configuration config) {
config.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );

Class<?>[] resources = getAnnotatedClasses();
for ( Class<?> resource : resources ) {
cfg.addAnnotatedClass( resource );
config.addAnnotatedClass( resource );
}

serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
factory = cfg.buildSessionFactory( serviceRegistry );
StandardServiceRegistryBuilder serviceBuilder = new StandardServiceRegistryBuilder( );
serviceBuilder.addService( ClassLoaderService.class, new ClassLoaderServiceImpl( Thread.currentThread().getContextClassLoader() ) );

serviceBuilder.applySettings( config.getProperties() );
serviceRegistry = serviceBuilder.build();
factory = config.buildSessionFactory( serviceRegistry );
}

public final void complete() {
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
Expand Down

0 comments on commit 8053fa7

Please sign in to comment.