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]