Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [TENEO] resource.save(null) -> Exception and then?
[TENEO] resource.save(null) -> Exception and then? [message #719683] Sun, 28 August 2011 11:57 Go to next message
Waldi  is currently offline Waldi Friend
Messages: 60
Registered: July 2009
Member
The old story: You save the resource and a Exception occur. In example a StaleObjectStateException occur because a client has updated rows in the database and a secound client try the same. What is the right way to handle the exception? I try to rollback the transaction und refresh the resource but with no success. The Error doesn't gone.

Thanks

Waldi
(no subject) [message #719701 is a reply to message #719683] Sun, 28 August 2011 13:30 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Waldi,
Yes, afaics there is not much that can be done about it, after an exception the hibernate session can not be used anymore...

Another solution could be to recreate the session, add the content of the resource to the new session and refresh the
objects from the database. You have overridden the HibernateResource isn't it? Do you have enough info to try this?

>>> a way to reattach an object to a session <<<
If you are sure that your entity has not been modified (or if you agree any modification will be lost), then you may
reattach it to the session with lock.

session.lock(entity, LockMode.NONE);
It will lock nothing, but it will get the entity from the session cache or (if not found there) read it from the DB.

gr. Martin

On 08/28/2011 01:57 PM, Waldi wrote:
> The old story: You save the resource and a Exception occur. In example a StaleObjectStateException occur because a
> client has updated rows in the database and a secound client try the same. What is the right way to handle the
> exception? I try to rollback the transaction und refresh the resource but with no success. The Error doesn't gone.
>
> Thanks
>
> Waldi


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
(no subject) [message #719859 is a reply to message #719701] Mon, 29 August 2011 07:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 28.08.11 15:30, schrieb Martin Taal:
> Hi Waldi,
> Yes, afaics there is not much that can be done about it, after an
> exception the hibernate session can not be used anymore...
>

Couldn't he simply invoke refresh(Object) on the session? Why create a
new one?

We are not working with resources in our application but we used to make
a refresh() in former version of the application but lately we
implemented something much cleverer because we record all change
commands on a object graph while editing, reapply/merge them on the
refresh object graph.

Tom
(no subject) [message #719873 is a reply to message #719859] Mon, 29 August 2011 09:24 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes, maybe,.. but according to the hibernate docs, if an exception occurs then the session can be in an invalid state
and should be discarded. That's at least the official statement, my guess is that often you can still use the session,
so it is a bit trial and error.

The object can be refreshed but the exception can be thrown deep in the hibernate code, when catching the exception you
don't know which object it failed on (guessing here). So it is difficult to refresh then.

gr. Martin

On 08/29/2011 09:52 AM, Tom Schindl wrote:
> Am 28.08.11 15:30, schrieb Martin Taal:
>> Hi Waldi,
>> Yes, afaics there is not much that can be done about it, after an
>> exception the hibernate session can not be used anymore...
>>
>
> Couldn't he simply invoke refresh(Object) on the session? Why create a
> new one?
>
> We are not working with resources in our application but we used to make
> a refresh() in former version of the application but lately we
> implemented something much cleverer because we record all change
> commands on a object graph while editing, reapply/merge them on the
> refresh object graph.
>
> Tom


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
(no subject) [message #719874 is a reply to message #719873] Mon, 29 August 2011 09:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 29.08.11 11:24, schrieb Martin Taal:
> Yes, maybe,.. but according to the hibernate docs, if an exception
> occurs then the session can be in an invalid state and should be
> discarded. That's at least the official statement, my guess is that
> often you can still use the session, so it is a bit trial and error.
>
> The object can be refreshed but the exception can be thrown deep in the
> hibernate code, when catching the exception you don't know which object
> it failed on (guessing here). So it is difficult to refresh then.
>

Well you get all information from the exception:
* StaleObjectException#getEntityName()
* StaleObjectException#getIdentifier()

We are using this information to present load the object in fresh
session and present a meaningful error message :-)

Tom
(no subject) [message #719879 is a reply to message #719874] Mon, 29 August 2011 09:49 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Good tip, thanks Tom!

gr. Martin

On 08/29/2011 11:30 AM, Tom Schindl wrote:
> Am 29.08.11 11:24, schrieb Martin Taal:
>> Yes, maybe,.. but according to the hibernate docs, if an exception
>> occurs then the session can be in an invalid state and should be
>> discarded. That's at least the official statement, my guess is that
>> often you can still use the session, so it is a bit trial and error.
>>
>> The object can be refreshed but the exception can be thrown deep in the
>> hibernate code, when catching the exception you don't know which object
>> it failed on (guessing here). So it is difficult to refresh then.
>>
>
> Well you get all information from the exception:
> * StaleObjectException#getEntityName()
> * StaleObjectException#getIdentifier()
>
> We are using this information to present load the object in fresh
> session and present a meaningful error message :-)
>
> Tom


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (no subject) [message #720566 is a reply to message #719879] Tue, 30 August 2011 20:17 Go to previous message
Waldi  is currently offline Waldi Friend
Messages: 60
Registered: July 2009
Member
thanks for the info's. I have to think about it
Previous Topic:[CDO] Multiple version edition & Parents version
Next Topic:[TENEO] Discard changes on resource
Goto Forum:
  


Current Time: Thu Apr 25 23:30:19 GMT 2024

Powered by FUDForum. Page generated in 0.03098 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top