Thanks very much for the reply. I am managing transactions programatically with TransactionTemplate, and the boundaries of each transaction should be the start and end of each execute() method, because the relevant code looks like this:
Code:
public void process(final IExecutable cmd) {
final PrintWriter output = getOutputWriter();
// Execute the command within a transaction created by the transactional template
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
final Element result = cmd.execute();
output.println(result.asXML());
} catch (Exception e) {
// Instruct Spring to rollback the transaction
status.setRollbackOnly();
throw new ExecutionException(e);
}
}
});
}
The implementation of cmd.execute() contains the following code:
Code:
Customer customer = dao.getCustomer(name);
List<Order> orders = customer.getOrders();
When customer.getOrders() is called a LazyInitializationException is thrown. The exception message indicates that the session has closed, or there is no session, so I can only assume that the session is being closed once the DAO method has completed.
However, you said in your reply:
Everything will use the same session until the session is closed and removed from the thread local
So it seems that the session should only be closed when doInTransactionWithoutResult() has completed.