Hello everyone.
I have some java code and the commit closes automaticly the session.
do I do some thing wrong
i always give error => connection already closed
or how can i make the code better ( just learning java)
Thx for helping me
Bert
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Bestellingt tmpa = new Bestellingt();
tmpa.setBesteldate(new Date());
Producten tmpProd = new ProductHelper().getProdById(10);
session.saveOrUpdate(tmpa);
for (int i = 0; i < 5; i++) {
Bestellijnt bestellijntsT = new Bestellijnt(tmpa, tmpProd, i, tmpProd.getProdprijs(), new Date());
session.saveOrUpdate(bestellijntsT);
}
System.out.println("voor commit:" + session.isConnected());=> here is the session open
tx.commit();
System.out.println("voor commit:" + session.isConnected());=> here is the session closed
} catch (Exception e) {
System.out.println("1 try:" +e.getStackTrace());
}
finally{
try {
session.close();
} catch (Exception e) {
// TODO: handle exception
System.out.println("2 try:" + e.getStackTrace());
}
}