|
(no subject) [message #719701 is a reply to message #719683] |
Sun, 28 August 2011 13:30 |
Martin Taal 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 #719873 is a reply to message #719859] |
Mon, 29 August 2011 09:24 |
Martin Taal 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 #719879 is a reply to message #719874] |
Mon, 29 August 2011 09:49 |
Martin Taal 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03098 seconds