2017-10-20 2 views
0

jerseyspring boot jpahibernate으로 사용하여 나머지 API를 통해 데이터베이스를 쿼리하려고합니다. 스프링 부트 + jpa + 저지가 프록시 초기화 할 수 없음 - 세션 없음

내 컨트롤러 방법 :

public SomeValue doSomething(String param) { 

    MyEntity entity = myService.queryDB(param); 
    return conv.convertEntity(entity); 
} 

내 서비스 :

엔티티

@Transactional 
public MyEntity queryDB(String param) { 
    return myRepo.findOne(param); 
} 
:

:

@Entity 
MyEntity { 

@Id 
@NotNull 
private String Id; 
@OneToMany(mappedBy="foreignKey", fetch = FetchType.LAZY) 
private Set<SomeOtherEntity> someOtherEntity; 

} 

은 심지어 명시 적으로 application.yml의 속성을 설정나는 봄의 OpenEntityManagerInViewInterceptorpreHandle 방법은 내가 저장소에 전화를 걸 다음에 호출되는 것을 볼 수 있습니다 디버깅하는 동안

failed to lazily initialize a collection of role: entitites.MyEntity.someOtherEntity, could not initialize proxy - no Session 

:

나는 다음과 같은 예외를 얻을. 전에 부르면 안되니?

이 예외/동작을 유발할 수있는 원인은 무엇입니까? 내 설정에 어떤 문제가 있습니까?

답변

0

그것의이 예외 편집 코드에 시도하고 대신를 사용하는 원인이 게으른 모드 :

@OneToMany(mappedBy="foreignKey", fetch = FetchType.EAGER) 
private Set<SomeOtherEntity> someOtherEntity; 
관련 문제