[jboss-user] [EJB 3.0] New message: "Re: Legacy app as a service POJO, using EJB3, Hibernate and BMT..."

jaikiran pai do-not-reply at jboss.com
Tue Mar 16 14:46:00 EDT 2010


User development,

A new message was posted in the thread "Legacy app as a service POJO, using EJB3, Hibernate and BMT...":

http://community.jboss.org/message/532343#532343

Author  : jaikiran pai
Profile : http://community.jboss.org/people/jaikiran

Message:
--------------------------------------------------------------
> sepan77 wrote:
>  
> 
> So far, so good. Everything seems to work fine, but sometimes the database transactions are not committed. This is actually very strange and happens most of the time when the application server is under load, but this behaviour is rather irrational to me.
It's hard to say what might be wrong, with the limited data.
 
> sepan77 wrote:
>  
> 
> 
>    @PersistenceUnit SessionFactory factory;  // <--- injected session factory, since app uses hibernate
>  
>    // lazy initialization of application
>    *private* MyApp getAppInstance() {
>       *if* (appInstance == *null*) {
>          appInstance = *new* MyApp();
>          Session session = factory.openSession();
>          *try* {
>            appInstance.configureFromDb(session);
>          } *catch* (Exception ex) {
>            ...
>          } *finally* {
>             *try* { session.close(); } *catch* (Exception ex) {}
>          }
>       }
>       *return* appInstance;
>    }
>  
>  
> 
Why are you using a sessionfactory (a.k.a PersistenceUnit) instead of a container managed @PersistenceContext (a.k.a EntityManager)?
 
By the way, you might want to use the latest stable AS 5.1.0 since there have been a lot of changes in EJB3 between 4.2.x and AS-5

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/532343#532343




More information about the jboss-user mailing list