Hibernate Session is closed when facing AuthenticationException

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Hibernate Session is closed when facing AuthenticationException

Joshua Partogi-2
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Session is closed when facing AuthenticationException

Les Hazlewood
Administrator
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 <[hidden email]>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
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Session is closed when facing AuthenticationException

Joshua Partogi-2
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 <[hidden email]> 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 <[hidden email]>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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Session is closed when facing AuthenticationException

Joshua Partogi-2
In reply to this post by Les Hazlewood
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 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Session is closed when facing AuthenticationException

Les Hazlewood-2
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 <[hidden email]>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 <[hidden email]> 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
>
Loading...