2016-07-15 4 views
0

현재 스레드 addDepartment 컨트롤러에 대한 발견 나는이 내 XML에 추가하고 있는가상자의 예외는 org.hibernate.HibernateException입니다 : 없음 세션이 나는 새로운 부서를 등록하려고

HTTP Status 500 - Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread 

이 오류가 파일 에러가 계속

<tx:annotation-driven transaction-manager="hibernateTransactionManager"/> 
    <!-- Scans within the base package of the application for @Component classes to configure as beans --> 
    <context:component-scan base-package="com.xxx.account.*"/> 

이 예외를 발생 컨트롤러 방법

@RequestMapping(value = "/addDepartment", method = RequestMethod.GET) 
    public ModelAndView addCategory(@ModelAttribute("command") Department department, 
      BindingResult result) { 
     Map<String, Object> model = new HashMap<String, Object>(); 
     model.put("department", departmentService.getDepartments()); 
     return new ModelAndView("addDepartment"); 
    } 
,

이 나는 ​​컨트롤러 방법

org.hibernate.HibernateException: No Session found for current thread 
    org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) m.chuma.account.dao.DepartmentDaoImpl.getDeparments(DepartmentDaoImpl.java:31)com.chuma.account.service.impl.DepartmentServiceImpl.getDepartments(DepartmentServiceImpl.java:28) 

이를 액세스하려고 할 때 나는 데 오류의 전체 스택 트레이스이다는

@Service("departmentService") 
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 
public class DepartmentServiceImpl implements DepartmentService{ 


    @Autowired 
    private DepartmentDao departmentDao; 

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 
    public void addDepartment(Department department) { 
     departmentDao.addDepartment(department); 
    } 

모든 것이 괜찮아 보인다 @Transactional 주석이 부서 DAO이다 지금까지 내 디버그에서,하지만 오류는 여전히보기를 반환하는 컨트롤러 메서드에 액세스하려고하면 유지됩니다. 무엇이 잘못되었거나 내가 누락 된 부분입니까?

+0

당신은 당신이에있는 hibernate.cfg.xml에 <속성 이름 = "current_session_context_class"> 스레드'또는'<키 = "의 hibernate.current_session_context_class를"소품> 스레드''같은 것을 가지고 있는지 확인하는 것이 좋습니다 스프링 설정에서'SessionFactoryBean'의 정의. –

+0

hibernate.cfg.xml 파일이 없다. – Blaze

+0

Spring XML 설정 파일이나'@ Configuration' 주석이 달린 자바 클래스에 Hibernate 속성 집합이 있는가? –

답변

0

왜 @Transactional 정의에 대해 propagation = Propagation.SUPPORTS를 읽지 않습니까? 이것은 메소드를 호출 한 곳에서 열린 트랜잭션이 이미있는 경우에만 메소드가 트랜잭션 컨텍스트에서 실행됨을 의미합니다.

Propagation을 사용하는 경우에도 동일한 문제가 발생합니다 .REQUIRED?

+0

이 문제가 해결되었습니다. – Blaze

관련 문제