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