문제

public List<Examination> loadExaminations(int pID) {

    session = sessionFactory.openSession();
    session.setFlushMode(FlushMode.MANUAL);
    ManagedSessionContext.bind(session);
    session.beginTransaction();
    Patient tpatient = (Patient) session.get(Patient.class, pID);
    List<Examination> examinations = new LinkedList<>();
    if (tpatient.getExaminations()!=null)
    if (!tpatient.getExaminations().isEmpty()) { //I get the exception to this line
        examinations = (List<Examination>) tpatient.getExaminations();
    }
    ManagedSessionContext.unbind(sessionFactory);
    session.flush();
    session.getTransaction().commit();
    session.close();
    return examinations;
}

Exception:

org.hibernate.SessionException: Session is closed

I get the exception, but actually in the program it seems to be fine; everithing is happening as it should, but the exception is bothering me.

Thanks for the help!

올바른 솔루션이 없습니다

다른 팁

If written into your Hibernate Config file session close tag then no need to use session.close() method otherwise written session close tag into hibernate config file and remove session.close() statement.

Like following line written into hibernate config file.

<property name='transaction.auto_close_session'>true</property>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top