1
내 서비스 클래스의 init 메소드에서 DB의 일부 데이터를로드하려고하지만 "getResultList()"메소드를 호출하면 Exception을 throw합니다. "세션이 닫혔습니다".init-method의 getResultList()가 "세션 닫힘"
내 applicationContext.xml
는<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="testService" class="com.impl.TestServiceImpl" init-method="init" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
내 서비스 클래스 :이 오류 메시지
public Class TestServiceImpl implements TestService {
private EntityManager entityManager;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public void init() {
Query query = entityManager.createQuery("from myTable");
query.getResultList(); // this causes error...
}
}
입니다
:SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'testService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is
javax.persistence.PersistenceException: org.hibernate.SessionException: Session is
closed!
Caused by: javax.persistence.PersistenceException: org.hibernate.SessionException:
Session is closed!
at
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
그래서 내가 잘못 여기서 뭐하는거야? 이 문제를 어떻게 해결할 수 있습니까? 감사. 모든 TestServiceImpl
의
감사합니다, 호출 다른 빈의 비즈니스 메소드가 이미 서비스 클래스에 @Transactional 있었다 그런데, 일한 (에 넣어하는 것을 잊지 질문)하지만 거기에 있더라도 언급했듯이 그것은 효과가 없었을 것입니다. – Rizwan