@PersistenceContext
private EntityManager entityManager;
18:41:57,753 ERROR LazyInitializationException:42 - failed to lazily initialize a collection of role
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import br.mil.eb.dgp.avaliacao.test.SpringContextLoad;
public abstract class BaseTest extends TestCase {
private ApplicationContext context = null;
private EntityManagerFactory entityManagerFactory;
public BaseTest(final String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
this.context = SpringContextLoad.getInstance(this.getContextFiles()).getContext();
entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory");
EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
TransactionSynchronizationManager.bindResource(entityManagerFactory, new EntityManagerHolder(entityManager));
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager
.unbindResource(entityManagerFactory);
EntityManagerFactoryUtils.closeEntityManager(entityManagerHolder.getEntityManager());
context = null;
}
protected Object getBean(final String beanName) {
if (null == beanName || 0 == beanName.trim().length())
throw new IllegalArgumentException("Nome do bean não informado.");
return this.context.getBean(beanName);
}
protected String[] getContextFiles() {
return new String[] { "application.xml" };
}
protected ApplicationContext getApplicationContext() {
return this.context;
}
}
Pessoal, me ajudem aí, tem dois dias que estou tentando desenvolver isto, o chefe (na verdade é a chefe), vai me matar, rs rsrs.....
Obrigado.