Hi,
I have 2 methods:
Code:
public OrderHeader getOrder(long orderNumber) throws DatabaseException {
try {
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
try{
OrderHeader order = (OrderHeader)s.load(OrderHeader.class, new Long(orderNumber));
s.flush();
t.commit();
s.close();
return order;
}catch(HibernateException he) {
s.close();
t.rollback();
throw new DatabaseException("Trouble during order retrieve! - [" + orderNumber + "]!", he);
}
} catch(HibernateException he) {
throw new DatabaseException("Unable to retrieve order [" + orderNumber + "]", he);
}
}
public void saveOrder(OrderHeader order) throws DatabaseException {
try {
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
try{
s.save(order);
s.flush();
t.commit();
s.close();
}catch(HibernateException he) {
s.close();
t.rollback();
throw new DatabaseException("Trouble during saving order! - [" + order + "]!", he);
}
} catch(HibernateException he) {
throw new DatabaseException("Unable to save order [" + order + "]", he);
}
}
sessionFactory is defined as follow:
Code:
protected static final SessionFactory sessionFactory;
I first call saveOrder(order) and then getOrder(long) but then i get the exception.
What am i doing wrong?
Code:
net.sf.hibernate.HibernateException: Session is closed
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3250)
at net.sf.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:104)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:95)
at com.bertrams.berteShop.dao.BookingDAO.getOrder(BookingDAO.java:46)
at com.bertrams.berteShop.dao.TestBookingDAO.testOrderHeader(TestBookingDAO.java:55)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)