You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by Joshua Partogi <jo...@gmail.com> on 2008/08/26 20:35:49 UTC

Hibernate Session is closed when facing AuthenticationException

Dear all

When there is an AuthenticationException occurs, if using Hibernate
then Hibernate session will be closed. Does anyone know how to handle
this? So HibernateSession won't be closed when an
AuthenticationException occur. Please give me insights regarding this.

Best regards,

-- 
Setting a new landmark.
Blog: http://joshuajava.wordpress.com/
Twitter: http://twitter.com/thejavafreak

Re: Hibernate Session is closed when facing AuthenticationException

Posted by Joshua Partogi <jo...@gmail.com>.
Hi Les,

It certainly helps. I guess I applied your spring-hibernate sample
wrongly. I'm trying to figure out to get out of this error now.

Thanks for the insight.

Best regards,

On Wed, Aug 27, 2008 at 2:42 AM, Les Hazlewood <le...@hazlewood.com> wrote:
> Hi Joshua,
>
> As I understand it, this is strongly related to how your transaction
> boundaries are defined.  Hibernate would close the HibernateSession when a
> transaction is committed or rolled back (e.g. due to a RuntimeException).
>
> If a runtime exception is thrown (like the AuthenticationException), but you
> catch it before the code that started the transaction exits, the transaction
> won't be rolled back.
>
> Does that help?
>
> Les
>
> On Tue, Aug 26, 2008 at 2:35 PM, Joshua Partogi <jo...@gmail.com>wrote:
>
>> Dear all
>>
>> When there is an AuthenticationException occurs, if using Hibernate
>> then Hibernate session will be closed. Does anyone know how to handle
>> this? So HibernateSession won't be closed when an
>> AuthenticationException occur. Please give me insights regarding this.
>>
>> Best regards,
>>
>> --
>> Setting a new landmark.
>> Blog: http://joshuajava.wordpress.com/
>> Twitter: http://twitter.com/thejavafreak
>>
>



-- 
Setting a new landmark.
Blog: http://joshuajava.wordpress.com/
Twitter: http://twitter.com/thejavafreak

Re: Hibernate Session is closed when facing AuthenticationException

Posted by Les Hazlewood <lh...@apache.org>.
Hi Joshua,

It is a philosophical choice more than anything.  The open-source framework
landscape in general seems to be moving towards RuntimeException hierarchies
for framework code.  Take Hibernate for example - in Hibernate 2.x, they
used a checked-exception hierarchy.  In Hibernate 3, that same hierarchy was
changed to extend from RuntimeException instead.  Spring is also mostly
RuntimeException based.  We are for most of the same reasons.

The idea is that RuntimeException hierarchies allow the end-user of the
framework choice based on their needs - they can either catch the exception
and handle it accordingly, or they can let it bubble up and let something
else take care of it.  The application developer would know best how and
when to catch exceptions in a meaninful way, and RuntimeExceptions allow for
more flexibility in that regard.

However this approach requires more diligence from the framework development
team - they must clearly document each Exception class/subclass as well as
any method that could throw such exceptions.  It requires great JavaDoc.
But in my opinion, this is worth it - the documentation should be good
anyway, and the end-user gets the flexibility they want.

At least that's my take on it :)

Regards,

Les


On Tue, Aug 26, 2008 at 10:53 PM, Joshua Partogi <jo...@gmail.com>wrote:

> Hi Les,
>
> The problems is in using JPA entityManager inject to my spring bean
> using @PersistenceContext. I configured the injection manually and it
> works now. May I know the reason why are we using RuntimeException for
> AuthenticationException? Just to add my knowledge bank of JSecurity.
> :-D
>
> Cheers,
>
> On Wed, Aug 27, 2008 at 2:42 AM, Les Hazlewood <le...@hazlewood.com> wrote:
> > Hi Joshua,
> >
> > As I understand it, this is strongly related to how your transaction
> > boundaries are defined.  Hibernate would close the HibernateSession when
> a
> > transaction is committed or rolled back (e.g. due to a RuntimeException).
> >
> > If a runtime exception is thrown (like the AuthenticationException), but
> you
> > catch it before the code that started the transaction exits, the
> transaction
> > won't be rolled back.
> >
> > Does that help?
>
> --
> Setting a new landmark.
> Blog: http://joshuajava.wordpress.com/
> Twitter: http://twitter.com/thejavafreak
>

Re: Hibernate Session is closed when facing AuthenticationException

Posted by Joshua Partogi <jo...@gmail.com>.
Hi Les,

The problems is in using JPA entityManager inject to my spring bean
using @PersistenceContext. I configured the injection manually and it
works now. May I know the reason why are we using RuntimeException for
AuthenticationException? Just to add my knowledge bank of JSecurity.
:-D

Cheers,

On Wed, Aug 27, 2008 at 2:42 AM, Les Hazlewood <le...@hazlewood.com> wrote:
> Hi Joshua,
>
> As I understand it, this is strongly related to how your transaction
> boundaries are defined.  Hibernate would close the HibernateSession when a
> transaction is committed or rolled back (e.g. due to a RuntimeException).
>
> If a runtime exception is thrown (like the AuthenticationException), but you
> catch it before the code that started the transaction exits, the transaction
> won't be rolled back.
>
> Does that help?

-- 
Setting a new landmark.
Blog: http://joshuajava.wordpress.com/
Twitter: http://twitter.com/thejavafreak

Re: Hibernate Session is closed when facing AuthenticationException

Posted by Les Hazlewood <le...@hazlewood.com>.
Hi Joshua,

As I understand it, this is strongly related to how your transaction
boundaries are defined.  Hibernate would close the HibernateSession when a
transaction is committed or rolled back (e.g. due to a RuntimeException).

If a runtime exception is thrown (like the AuthenticationException), but you
catch it before the code that started the transaction exits, the transaction
won't be rolled back.

Does that help?

Les

On Tue, Aug 26, 2008 at 2:35 PM, Joshua Partogi <jo...@gmail.com>wrote:

> Dear all
>
> When there is an AuthenticationException occurs, if using Hibernate
> then Hibernate session will be closed. Does anyone know how to handle
> this? So HibernateSession won't be closed when an
> AuthenticationException occur. Please give me insights regarding this.
>
> Best regards,
>
> --
> Setting a new landmark.
> Blog: http://joshuajava.wordpress.com/
> Twitter: http://twitter.com/thejavafreak
>