Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

erro com bidirecional failed to lazily initialize a collection of role

Bom dia pessoal estou com esse problema em um relacionamento @ManyToMany failed to lazily initialize a collection of role: br.com.sabium.cadastroprojeto.modelo.Employee.projects, could not initialize proxy

Acabei dando uma pesquisada e algumas pessoa falaram sobre o @JsonBackReference, mas não onde devo coloca-lo, tentei colocar ele em todo lugar mas não consegui alguém pode me ajudar

public class Employee{
    ...
    @ManyToMany
    private Set<Project> projects;
}

public class Project {
    ...
    @ManyToMany(mappedBy = "projects")
    private Set<Employee> employees;
}
<error type="org.jboss.arquillian.test.spi.ArquillianProxyException" message="org.hibernate.LazyInitializationException : failed to lazily initialize a collection of role: br.com.sabium.cadastroprojeto.modelo.Employee.projects, could not initialize proxy - no Session [Proxied because : Original exception not deserilizable, ClassNotFoundException]">org.jboss.arquillian.test.spi.ArquillianProxyException: org.hibernate.LazyInitializationException : failed to lazily initialize a collection of role: br.com.sabium.cadastroprojeto.modelo.Employee.projects, could not initialize proxy - no Session [Proxied because : Original exception not deserilizable, ClassNotFoundException]at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:567)at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:205)at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:146)at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143)at java.util.Collections$UnmodifiableCollection.size(Collections.java:1030)at br.com.sabium.cadastroprojeto.repository.test.EmployeeRepositoryTest.deveSalvarUmEmployeeEmDoisProjectDiferestes(EmployeeRepositoryTest.java:106) </error>
2 respostas
solução!

Olá Matheus!

Tenta colocar na anotação ManyToMany dos projetos:

fetch=FetchType.EAGER

Dessa forma:

@ManyToMany(fetch=FetchType.EAGER)
private Set<Project> projects;

Veja se funciona pra ti!

Aguardo sua resposta.

Vlw Guilherme funcionou aqui

Results :

Tests run: 18, Failures: 0, Errors: 0, Skipped: 0

BUILD SUCCESS

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software