How to handle exceptions while active transaction?

4 views
Skip to first unread message

Peter

unread,
Jul 22, 2010, 5:42:40 AM7/22/10
to warp-core
Hi,

I am using hibernate and would like to know how you would handle
StaleObjectStateException:s within a open transaction when using warp
persist.

Do I need to do the following:
1. leave the @Transactional-marked method
2. call manager.endWork()
3. call manager.beginWork()
to make it correctly working? Or what minimal code is required for
that?

Regards,
Peter.

Dhanji R. Prasanna

unread,
Jul 22, 2010, 11:08:06 AM7/22/10
to warp...@googlegroups.com
It depends on what your unit of work is, if it is REQUEST and you have a filter running you dont have to do anything coz the filter cleans up after you. Same with transaction strategy.

So the basic answer is you should do whatever you'd normally do in handling SOSE for hibernate, everything else should just work. If you're asking what causes SOSE and how to fix it, that maybe better answered by the hibernate folk =)

Dhanji.


--
You received this message because you are subscribed to the Google Groups "warp-core" group.
To post to this group, send email to warp...@googlegroups.com.
To unsubscribe from this group, send email to warp-core+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/warp-core?hl=en.


Peter

unread,
Jul 22, 2010, 5:12:18 PM7/22/10
to warp-core
Dear Dhanji,

thanks for the reply!

> if it is REQUEST and you have a filter running

But then I can't retry the transaction automatically (when it is
desired), right?

Just as a side note - on the hibernate forum I read [1]:
"AFAIK exceptions thrown by hibernate are not recovarable. You have to
rollback and close your session and start again. At least that was
true for H2, I'm not 100% sure for H3."

So for my usecase where I manage my sessions on my own with the
WorkManager the 3 steps above should be sufficient
(be sure that you re-attach the objects to the new session)

Regards,
Peter.

[1]
https://forum.hibernate.org/viewtopic.php?p=2266139

On Jul 22, 5:08 pm, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> It depends on what your unit of work is, if it is REQUEST and you have a
> filter running you dont have to do anything coz the filter cleans up after
> you. Same with transaction strategy.
>
> So the basic answer is you should do whatever you'd normally do in handling
> SOSE for hibernate, everything else should just work. If you're asking what
> causes SOSE and how to fix it, that maybe better answered by the hibernate
> folk =)
>
> Dhanji.
>
> On Thu, Jul 22, 2010 at 7:42 PM, Peter <tableyourt...@googlemail.com> wrote:
> > Hi,
>
> > I am using hibernate and would like to know how you would handle
> > StaleObjectStateException:s within a open transaction when using warp
> > persist.
>
> > Do I need to do the following:
> > 1. leave the @Transactional-marked method
> > 2. call manager.endWork()
> > 3. call manager.beginWork()
> > to make it correctly working? Or what minimal code is required for
> > that?
>
> > Regards,
> > Peter.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "warp-core" group.
> > To post to this group, send email to warp...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > warp-core+...@googlegroups.com<warp-core%2Bunsu...@googlegroups.com>
> > .

Dhanji R. Prasanna

unread,
Jul 25, 2010, 2:59:33 AM7/25/10
to warp...@googlegroups.com
On Fri, Jul 23, 2010 at 7:12 AM, Peter <tabley...@googlemail.com> wrote:
Dear Dhanji,

thanks for the reply!

> if it is REQUEST and you have a filter running

But then I can't retry the transaction automatically (when it is
desired), right?


Im not sure I follow--why not? It depends on the exception entirely. You can just call the method again with fixed arguments if it is a NoResultException for example, and it will run in a new transaction.
 
Just as a side note - on the hibernate forum I read [1]:
"AFAIK exceptions thrown by hibernate are not recovarable. You have to
rollback and close your session and start again. At least that was
true for H2, I'm not 100% sure for H3."

I don't buy this, JPA throws many exceptions in cases where it is trying to report an empty list for example. It should certainly be recoverable (not all are, of course). In any case Hibernate 3 has been the standard for several years now, so the comment may be out of date.


So for my usecase where I manage my sessions on my own with the
WorkManager the 3 steps above should be sufficient
(be sure that you re-attach the objects to the new session)

I would not reattach, instead I would query them out again as fresh objects. Reattach is a recipe for all kinds of complications =)

In any case, I believe this question is heading toward very Hibernate and JPA specific stuff, and I have not worked in that area for awhile.

Dhanji.

Peter

unread,
Jul 26, 2010, 5:48:28 AM7/26/10
to warp-core
Dhanji,

thanks again for your comments! I will try to get a deeper
understanding of that. (e.g. in the hibernate forum or somewhere)

> I would not reattach, instead I would query them out again as fresh objects.
> Reattach is a recipe for all kinds of complications =)

Ah okay. That sounds good. I will try it :-)

Kind regards,
Peter.

On Jul 25, 8:59 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages