I pray to you, an aid!
I use Hibernate (2.1.8), webwork (2.1.7), Bea (8,1 sp4)
view side
- I recover the hibernate session in every webwork action
- I have static methods ("manager") that save, update, delete my objects. I always give to these method the hibernate-session
ejb side
many task are launched in contemporary through JMS and approach in competitive way the data (as an example a counter of sended messages that is decremented from the MDB itself at the end its life)
There is someone who can tell me, with detailed example (code), in that way I must manage transacion (JTA) in my MDB?
Can I have an example of code in which a query is executed, the object is modified, updated and if something goes bad a rollback is made?
What is the right architecture for that???
[u]Thank you very match!!![/u]
I leave also an example of my code and the the problems that I have with the transactions
Hibernate version:2.1.8
Mapping documents:
Code:
### Oracle
hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
hibernate.connection.datasource jdbc/PRODataSource
hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
## JTA
hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#jta.UserTransaction javax.transaction.UserTransaction
hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#GENERAL
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
hibernate.show_sql false
hibernate.jdbc.batch_size 0
hibernate.jdbc.use_scrollable_resultset true
hibernate.jdbc.use_streams_for_binary true hibernate.use_outer_join true
Code between sessionFactory.openSession() and session.close():
Code:
public String execute() {
Session ss = null;
Transaction tx = null;
try {
ss = ApplicationManager.getInstance().getHibernateSession(ApplicationManager.getInstance().getProperty("application.dbAlias"));
tx = ss.beginTransaction();
User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
try {
dayWorkSession = DayWorkSessionManager.getDayWorkSession(dayWorkSession.getId(), ss);
dayWorkSession.getUserInputFiles().size();
DayWorkSessionManager.lockDayWorkSession(dayWorkSession, user.getUser(), ss);
ss.update(dayWorkSession);
tx.commit();
}catch(Exception e) {
log.error("Error UserLock");
try {
if (tx != null) tx.rollback();
} catch (HibernateException he) {
log.error("", he);
}
}finally{
HibernateUtils.close(ss);
}
}catch(Exception e1) {
log.error("Error " + e1);
}
return SUCCESS;
}
Stack trace exception that occurs:
2006-09-01 13:29:46,343 [ERROR] util.JDBCExceptionReporter:38 - Could not execute query
java.sql.SQLException: The transaction is no longer active - status: 'Committed'. No further JDBC access is allowed within this transaction.
at weblogic.jdbc.wrapper.JTSConnection.checkIfRolledBack(JTSConnection.java:219)
at weblogic.jdbc.wrapper.JTSConnection.checkConnection(JTSConnection.java:228)
at weblogic.jdbc.wrapper.Connection.prepareStatement(Connection.java:356)
at weblogic.jdbc.wrapper.JTSConnection.prepareStatement(JTSConnection.java:544)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:257)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:232)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:65)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at it.enel.sirap.pro.utils.HibernateUtils.loadListFromQueryString(HibernateUtils.java:73)
...