These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Right architecture and example of use of the jta in mdb
PostPosted: Fri Sep 01, 2006 11:50 am 
Newbie

Joined: Wed Jul 12, 2006 6:36 am
Posts: 5
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)

...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 2:02 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
If you can, consider upgrading to Hibernate 3.1 as it out of the box support for integrating into a JTA environment. The Hibernate 2.x series is way old now and you'll have to develop custom code to do the same thing in Hibernate 2.x.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 6:13 pm 
Newbie

Joined: Wed Jul 12, 2006 6:36 am
Posts: 5
Thank you very mutch for your reply.
I would like to use always the last release of every program but the logic of project's development often don't permit that and still more often there is fear of changing in run!
Our project was born two years ago as a little web application on Tomcat, now is a terrible monster that go round on two bea clusters so, as you can understand, it suffer all the problems of the case!
My real problem is that I am not able to find a good example of the standard usage of the jta inside an mdb enviroment. What is on the web is always too simple or too much different from my situation.
For me it would be useful also a good link to some mdb code that works in this way. But the only thing I have found is the petShop that isn't exactly an example of the usage of hibernate2 on an enterprise architecture.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.