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.  [ 5 posts ] 
Author Message
 Post subject: StaleStateException weblogic
PostPosted: Tue Aug 07, 2007 8:32 pm 
Newbie

Joined: Tue Aug 07, 2007 8:22 pm
Posts: 3
I have implemented a SLSB as my facade, and using Hibernate 3.2 for DAO. I use EJB2.0. This is deployed on weblogic9.2

I am trying to implement optimistic concurrency. When I get the message StaleObjectStateException, Hibernate does a setRollback.

I am not able to catch this exception in my EJB. The control never comes back to my EJB. I would like to catch it and throw a meaningful exception (OptimisticConcurrencyException) to the client.

What the CLient gets is weblogic.transaction.internal.AppSetRollbackOnlyException. How do I catch the StaleObjecTException.

Also, how is this different from a JDBC exception. When I get a JDBCException, the transaction is rolled back, but I get control in the exception block of my EJB

Also - will not a RuntimeException be automatically rolledback by a container. Is HibernateException not a RuntimeException? Then why is there a need to explicitly do a setRollBackOnly

EJB
public void update()
{
try{
dao.saveOrUpdate();
}
catch(Exception e) {
e.printStackTrace();l
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 7:04 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
How do you get hold of your DAO object?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 11:28 am 
Newbie

Joined: Tue Aug 07, 2007 8:22 pm
Posts: 3
EJB -> Calls a Service class (Plain java class), that calls DAO class.
All of them don't catch any exceptions. Only EJB has try/catch.

But when Session.saveOrUpdate is called, I don't get control back to my program at all.

Hibernate.config.xml
<property name="connection.datasource">MyDataSource</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction"</property>

<property name="current_session_context_class">jta</property>

<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>




protected Session getCurrentSession() {
logger.debug("Getting hibernate session");
return HibernateUtil.getSessionFactory().getCurrentSession();
}



public class HibernateUtil
{
private static final SessionFactory sessionFactory;
private static Logger logger = new Logger(HibernateUtil.class.getName());

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
logger.info("Got session Factory");
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
logger.fatal("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

public static Session getSession() {
return getSessionFactory().getCurrentSession();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 11:29 am 
Newbie

Joined: Tue Aug 07, 2007 8:22 pm
Posts: 3
EJB -> Calls a Service class (Plain java class), that calls DAO class.
All of them don't catch any exceptions. Only EJB has try/catch.

But when Session.saveOrUpdate is called, I don't get control back to my program at all.

Hibernate.config.xml
<property name="connection.datasource">MyDataSource</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction"</property>

<property name="current_session_context_class">jta</property>

<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>




protected Session getCurrentSession() {
logger.debug("Getting hibernate session");
return HibernateUtil.getSessionFactory().getCurrentSession();
}



public class HibernateUtil
{
private static final SessionFactory sessionFactory;
private static Logger logger = new Logger(HibernateUtil.class.getName());

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
logger.info("Got session Factory");
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
logger.fatal("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

public static Session getSession() {
return getSessionFactory().getCurrentSession();
}

}


Top
 Profile  
 
 Post subject: try writing custom Flush Event listener
PostPosted: Thu Aug 09, 2007 12:54 am 
Newbie

Joined: Wed Aug 08, 2007 11:44 pm
Posts: 4
Location: Denver
Write customized flush event listener by extending 'DefaultFlushEntityEventListener' event listener(Configure this eventlistener to SessionFactory)....Override 'onFlushEntity' method....put 'super.onFlushEntity' in try/catch block...catch 'StaleObjectStateException' and throw whatever exception you want to throw...

Hope it works.


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