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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Little bug in SessionFactoryImpl.getCurrentSession()
PostPosted: Wed May 18, 2005 6:04 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
In Hibernate 3.0.3 I've found this problem:

Code:
java.lang.NullPointerException
        at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:511)
...


This happens if there's no current transaction. I think a NPE should be catched for better error handling.

Code:
      Transaction txn = null;
      try {
         txn = transactionManager.getTransaction();
         if ( !JTAHelper.isInProgress( txn.getStatus() ) ) {
-----------------------------------------^
            throw new HibernateException( "Current transaction is not in progress" );
         }
      }
      catch( SystemException se ) {
         throw new HibernateException( "Unable to locate current transaction" );
      }


I'm using the EJB façade pattern, and I've solved setting transaction to Required.

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 9:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not sure how to make it any more clear than it is in the docs now; a transaction must be in progress in order to use getCurrentSession().

Sure, I can make the error message more explicit if you like.

Maybe I should makethe message have a link to the documentation ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 9:31 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
I mean:

Code:
if ( txn == null || !JTAHelper.isInProgress( txn.getStatus() ) ) {


instead of

Code:
if ( !JTAHelper.isInProgress( txn.getStatus() ) ) {


The message is clear enough, if it is displayed !

_________________
--
Marco


Top
 Profile  
 
 Post subject: getcurrentSession during jboss startup
PostPosted: Wed May 18, 2005 11:53 am 
Newbie

Joined: Wed May 18, 2005 11:29 am
Posts: 1
i have a mbean loading during jboss startup that calls a session ejb and when i use getCurrentSession() it throws the same null error. the same ejb call works fine after jboss finishes booting. i figure its some dependency issue.

my session bean transaction = 'required'

and the dep on the mbean are:
<depends>jboss:service=proxyFactory,target=ClientUserTransactionFactory</depends>
<depends>jboss:service=proxyFactory,target=ClientUserTransaction</depends>
<depends>jboss:service=TransactionManager</depends>
<depends>jboss:service=ClientUserTransaction</depends>

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 12:15 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Just a hint: MBean use the current thread for enqueueing and a different thread for execution, so the current transaction (if created using UserTransaction.begin(), that binds it to current thread) is not available.
Check the documentation for this, I cant say for sure...

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Huh?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 10:33 am 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
Can I use the getCurrentSession() in a stateless EJB where the method transaction attribute has been declared as 'NotSupported'.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:08 pm 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
gavin wrote:
No.


Any soultions? I want to make calls to getCurrentSession in my EJB's as transparent as possible. If the method does not support transaction what are my options to get a session ? IMHO , getCurrentSession should return a session even in a method where the transaction Attribute is 'NotSupported'.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:15 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Why you don't want transaction? What's wrong with it?

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Um. *Think* about what you are asking for!

What should be the scope of the "current" session when there is no transaction?????

Outside of a transaction, the only scope that makes sense is per-operation. So use openSession()/close(). What would you want to use getCurrentSession() for??


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:28 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
In a servlet environment, another interesting scope is the servlet request.
That's to say:
- create the session and store it as a request attribute
- flush & close it in a filter, after the servlet execution.

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:38 pm 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
gavin wrote:
Um. *Think* about what you are asking for!

What should be the scope of the "current" session when there is no transaction?????

Outside of a transaction, the only scope that makes sense is per-operation. So use openSession()/close(). What would you want to use getCurrentSession() for??


Exactly, the scope will be per-operation. With auto close and auto flush features in Hibernate 3.0.2 and above , my understanding is I will always use getCurrentSession() in all my methods . If there is no transaction defined , Hibernate will return a new session.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 4:34 pm 
Newbie

Joined: Thu May 05, 2005 5:57 pm
Posts: 7
Location: California, USA
A related question...and I apologize if this has been posted. This topic is the closest I could find after performing a search.

I am currently using getCurrentSession() in Hibernate 3.0.5 on JBoss 4.0.2 with session facades.

My understanding is the Sessionobjects returned by getCurrentSession()would have the auto-close attribute set to true. But if I don't explicitly close the Session, I get this message from JBoss:

14:01:43,261 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@bbddbf

Does anyone know what I am missing here? Or is this the normal behavior? It is kind of a drag if the message is expected. Since this message does pop up a lot and kind of implies the progammer was being sloppy, which is not the impression I would want to give to our customers, who would have access to the logs.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 28, 2005 1:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That should not happen if aggressive connection release is working. You should check the log to see that connection is getting closed after each SQL operation.


Note that aggressive connection release requires "help" if you are using scroll() and iterate(). Check the docs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.