Question

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!

No correct solution

OTHER TIPS

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>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top