sbErrorMessage.append("Could not open or inject a Hibernate Session in ValueStack: ");
sbErrorMessage.append(e.getMessage());
String message = sbErrorMessage.toString();
System.err.println(message);
e.printStackTrace();
throw new SessionInjectionException(message);
}
if (!sessionNotInjected) {
try {
if (transactionTarget!=null && (!transactionTarget.equals(""))) {
injectHibernateTransactionByConfiguration(fields, injectedSessions, invocation);
}
injectHibernateTransactionByAnnotation(action, injectedSessions.iterator().next(), false);
for (Session hibernateSession:injectedSessions) {
Transaction hibernateTransation = hibernateSession.getTransaction();
if (!hibernateTransation.isActive())
hibernateTransation.begin();
}
} catch (Exception e) {
sbErrorMessage.append("Could not open or put a Hibernate Transaction in ValueStack: ");
sbErrorMessage.append(e.getMessage());
String message = sbErrorMessage.toString();
System.err.println(message);
e.printStackTrace();
throw new TransactionException(message);
}
}
}
String returnName = "";
try {
// ServletActionContext.getRequest().setAttribute("ss", injectedSessions.iterator().next().hashCode());
returnName = invocation.invoke();
for (Session hibernateSession:injectedSessions) {
Transaction hibernateTransation = hibernateSession.getTransaction();
try {
commitHibernateTransaction(hibernateTransation);
closeHibernateSession(hibernateSession);
log.debug("Hibernate Transaction Committed");
}
catch (Exception e) {
hibernateSession.clear();
sbErrorMessage.append("Could not commit the Hibernate Transaction: ");
sbErrorMessage.append(e.getMessage());
String message = sbErrorMessage.toString();
System.err.println(message);
closeHibernateSession(hibernateSession);
detectAndCloseHibernateCoreSessionCreatedLater(action);
e.printStackTrace();
throw new SessionInjectionException(message);
}
}
detectAndCommitHibernateTransactionCreatedLater(action);