내 저장소 '@PostConstruct
에서 일부 데이터베이스 물건을 할 :@PostConstruct 및 "스레드에 바인드 된 하이버 네이트 세션 없음"예외
@Repository
public class SomeRepositoryHibernate implements SomeRepository {
private SessionFactory sessionFactory;
@Autowired
public SomeRepositoryHibernate(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
...
@PostConstruct
public void doSomestuffWithDb() {
...
}
}
하지만 함께 실패합니다 :
org.hibernate.HibernateException: No Hibernate Session bound to thread, and
configuration does not allow creation of non-transactional one here
거기에 어떤 쉬운 솔루션이 있습니까?
고마워!
1)에서 JIRA에 자신의 솔루션을 제출 - 다른 컨테이너가 나는 @Autowired 표기법의 존재를 주어 믿고있어 봄 (다른 시간에 PostConstruct의 처리 때문에 중요한). 2) "doSomestuffWithDB"에서 실제로하고있는 일과 sessionFactory를 초기화하는 방법은 수명주기의 해당 시점에서 수행하는 작업에 영향을 미칩니다. – lscoughlin
1) 저는 현재 부두에서 실행합니다 - 다른 사람들에게 테스트하지 않았습니다. 2) 난 그냥 세션을 최대 절전 모드로 얻을 수 없다 - sessionFactory.getCurrentSession(), 그래서 아무것도 할 수 있습니다. 감사합니다 –
내 세션은 단지 –