-->
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.  [ 2 posts ] 
Author Message
 Post subject: ejb transaction and hibernate
PostPosted: Mon Jan 03, 2005 5:19 am 
Newbie

Joined: Fri Dec 24, 2004 8:32 am
Posts: 3
Location: Paris
Hello everyone.
First of all, happy new year !

Well, the fact is I'm having a little problem using hibernate in
a Stateless Session Bean.

I just wanted to let EJB managed the transaction. So I writed EJB in wich
I call my Hibernate Code. My problems occurs when I try to reuse one of my EJB in another new one.
For Example, I'have an EJB method wich add an Address in the database.
Fine It works very well. But When I wrote an EJB to add a contract in my database, I just want to reuse the 'Add Address' code. The fact is if there's no problems all works fine. But let say an Exception occurs betwen my 'Add Adress Code' and my 'Add contract code'. The fact is taht in this case
the Add Contract code is rollbacked but not the Add Address code.

I've checked, my EJB are configured to work in a 'REQUIRED' mode. So
the transaction should be propagated. Here's comes my information, I hope you could help me with this problems.

Hibernate version:

2.0

Code between sessionFactory.openSession() and session.close():

Code:
public class GlobalServiceEJB implements SessionBean

{

   // this class manage the hibernate session
  private HibernateHelper helper = null;

 

  public void ejbCreate() throws CreateException

  {

        try {

            helper = HibernateHelper.getInstance();

        } catch (HibernateException e) {

            Throwable t = ExceptionUtils.getRootCause(e);

            String message = (t != null) ? t.toString() : e.toString();

            throw new CreateException(message);

        }

  }

 

 





  public void update(ContextBean cbean, Object obj) throws UserSessionException

  {

        Session session = null;

               

        try {
             // I retrive the hibernate session
            session = helper.getSession(cbean.getDbUrl());

            // I retrieve my other EJB
            InsertService ins = ((InsertServiceHome) ServiceLocator.getInstance().getRemoteHome("InsertService", InsertServiceHome.class)).create();

            UpdateService upd = ((UpdateServiceHome) ServiceLocator.getInstance().getRemoteHome("UpdateService", UpdateServiceHome.class)).create();

           
            Long l = (Long) ins.insert(cbean, obj);

            TestEJB t = new TestEJB();

            t.setLigne(l);

            t.setTexte("THIS IS AN UPDATE ");

            // Processing some data
            // Let say An Exception occurs here the insert wont be roll back

            upd.update(cbean, t);

           

        } catch (Exception e) {

            session.clear();

            throw new UserSessionException(e.getMessage(), e); 

        } finally {

            helper.closeSession(session);

        }

  }

 

}




Name and version of the database you are using:
Oracle 9.2.0.4

Application Server :
Oracel application Server

IDE :
Jdevelopper 10G



thanks for your future response.

Kindest Regard

Tony




[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 10:59 am 
Newbie

Joined: Fri Dec 24, 2004 8:32 am
Posts: 3
Location: Paris
oki !

i found the solution myself ...

the fact is that I forgot to use the SessionContext of my Session bean ....

Lol !
I now undestand why none of you answered ....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.