Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Undo / Redo resource save issue
[Teneo] Undo / Redo resource save issue [message #449789] Sat, 01 August 2009 06:39 Go to next message
Matt Biggs is currently offline Matt BiggsFriend
Messages: 71
Registered: July 2009
Member
Hi Martin,

I'm having a bit of a problem with my resource when attempting to save.

Pressume my model consists of ClassA which contains a collection of ClassB.


1. Create/Load a resource with a ClassA object in it.
2. Save resource. Ok
3. Add a new instance of ClassB to ClassA.
4. Save resource. Ok
5. Undo command stack (removing ClassB).
6. Save resource. Ok
7. Redo command stack (re-adding ClassB).
8. Save resource. FAIL.

Depending on if the relationship is a containment one or not, i seem to
get one of two exceptions.

Containment gives me:

org.hibernate.StaleObjectStateException: Row was updated or deleted by
another transaction (or unsaved-value mapping was incorrect): [ClassB#1]

Reference gives me:

org.hibernate.HibernateException: Found two representations of same
collection: ClassA.classb


Is this something to do with cascading?

cheers

Matt
Re: [Teneo] Undo / Redo resource save issue [message #455630 is a reply to message #449789] Sat, 01 August 2009 20:39 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Matt,
For the containment what fails is that probably ClassB still has its id/version set. So when resaving the instance (step
8) Hibernate will try to do an update instead of a save. Hibernate does an update with select and checks the count of
the updated objects. The select contains the id and version values as select criteria. As the object has been removed
the update will return 0 updated objects and hibernate will throw the stale-object exception. So to solve this you
should set the id/version of the object to zero (between step 6 and 7). If the object does not have an excplicit
id/version eattribute then you should call the IdentifierCacheHandler methods (check the interface to see what method to
call).
You could say the hibernate resource should set the id/version to null/zero for new objects. However, as the resource
can be filled with queries and does not correspond to a xml resource it is not clear if a new object in the resource is
really a new object in the database.

Can you try if the above helps?

Regarding when it is a reference, this exception I do not yet understand. I understand what it means but I do not
understand why it occurs.

Can you make a testcase (or a testmodel with pseudo code) to reproduce this and enter a bugzilla for it? Then I can
check it.in more detail.

gr. Martin

Matt Biggs wrote:
> Hi Martin,
>
> I'm having a bit of a problem with my resource when attempting to save.
>
> Pressume my model consists of ClassA which contains a collection of ClassB.
>
>
> 1. Create/Load a resource with a ClassA object in it.
> 2. Save resource. Ok
> 3. Add a new instance of ClassB to ClassA.
> 4. Save resource. Ok
> 5. Undo command stack (removing ClassB).
> 6. Save resource. Ok
> 7. Redo command stack (re-adding ClassB).
> 8. Save resource. FAIL.
>
> Depending on if the relationship is a containment one or not, i seem to
> get one of two exceptions.
>
> Containment gives me:
>
> org.hibernate.StaleObjectStateException: Row was updated or deleted by
> another transaction (or unsaved-value mapping was incorrect): [ClassB#1]
>
> Reference gives me:
>
> org.hibernate.HibernateException: Found two representations of same
> collection: ClassA.classb
>
>
> Is this something to do with cascading?
>
> cheers
>
> Matt


--

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: [Teneo] Undo / Redo resource save issue [message #460669 is a reply to message #455630] Sun, 02 August 2009 09:22 Go to previous messageGo to next message
Matt Biggs is currently offline Matt BiggsFriend
Messages: 71
Registered: July 2009
Member
Martin,

The problem with changing the ID of the object is that its not always
easy to get to the model object.

I was simply calling commandstack.undo() etc to undo / redo the model.

As such in order to find the object i now have to walk the command
stacks redo command, looping through all child commands etc searching
for an AddCommand and then call the IdentifierCacheHandler's setId
method on its affected objects. I eventually managed to do this but then
ran into the 2nd exception i was receiving. So i'm still not sure if
that solves the problem.

I've knocked together a rather hacky :p testcase and model to reproduce
the issue and attached it to bug 285372.

Cheers

Matt



Martin Taal wrote:
> Hi Matt,
> For the containment what fails is that probably ClassB still has its
> id/version set. So when resaving the instance (step 8) Hibernate will
> try to do an update instead of a save. Hibernate does an update with
> select and checks the count of the updated objects. The select contains
> the id and version values as select criteria. As the object has been
> removed the update will return 0 updated objects and hibernate will
> throw the stale-object exception. So to solve this you should set the
> id/version of the object to zero (between step 6 and 7). If the object
> does not have an excplicit id/version eattribute then you should call
> the IdentifierCacheHandler methods (check the interface to see what
> method to call).
> You could say the hibernate resource should set the id/version to
> null/zero for new objects. However, as the resource can be filled with
> queries and does not correspond to a xml resource it is not clear if a
> new object in the resource is really a new object in the database.
>
> Can you try if the above helps?
>
> Regarding when it is a reference, this exception I do not yet
> understand. I understand what it means but I do not understand why it
> occurs.
>
> Can you make a testcase (or a testmodel with pseudo code) to reproduce
> this and enter a bugzilla for it? Then I can check it.in more detail.
>
> gr. Martin
>
> Matt Biggs wrote:
>> Hi Martin,
>>
>> I'm having a bit of a problem with my resource when attempting to save.
>>
>> Pressume my model consists of ClassA which contains a collection of
>> ClassB.
>>
>>
>> 1. Create/Load a resource with a ClassA object in it.
>> 2. Save resource. Ok
>> 3. Add a new instance of ClassB to ClassA.
>> 4. Save resource. Ok
>> 5. Undo command stack (removing ClassB).
>> 6. Save resource. Ok
>> 7. Redo command stack (re-adding ClassB).
>> 8. Save resource. FAIL.
>>
>> Depending on if the relationship is a containment one or not, i seem
>> to get one of two exceptions.
>>
>> Containment gives me:
>>
>> org.hibernate.StaleObjectStateException: Row was updated or deleted by
>> another transaction (or unsaved-value mapping was incorrect): [ClassB#1]
>>
>> Reference gives me:
>>
>> org.hibernate.HibernateException: Found two representations of same
>> collection: ClassA.classb
>>
>>
>> Is this something to do with cascading?
>>
>> cheers
>>
>> Matt
>
>
Re: [Teneo] Undo / Redo resource save issue [message #465358 is a reply to message #460669] Sun, 02 August 2009 21:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Matt,
I saw it.

I can make the resource smarter to assume that objects added to the resource are always new. This is also how EMF looks
at it.

I am quite busy at the moment, so it will take a week or so before I can spend time on this I am afraid.

In the meantime it should not be too difficult to extend the hibernate resource with your own implementation which takes
care of nulling the ids/versions of new objects in the resources. The new objects are stored in a separate arraylist in
the resource.

gr. Martin

Matt Biggs wrote:
> Martin,
>
> The problem with changing the ID of the object is that its not always
> easy to get to the model object.
>
> I was simply calling commandstack.undo() etc to undo / redo the model.
>
> As such in order to find the object i now have to walk the command
> stacks redo command, looping through all child commands etc searching
> for an AddCommand and then call the IdentifierCacheHandler's setId
> method on its affected objects. I eventually managed to do this but then
> ran into the 2nd exception i was receiving. So i'm still not sure if
> that solves the problem.
>
> I've knocked together a rather hacky :p testcase and model to reproduce
> the issue and attached it to bug 285372.
>
> Cheers
>
> Matt
>
>
>
> Martin Taal wrote:
>> Hi Matt,
>> For the containment what fails is that probably ClassB still has its
>> id/version set. So when resaving the instance (step 8) Hibernate will
>> try to do an update instead of a save. Hibernate does an update with
>> select and checks the count of the updated objects. The select
>> contains the id and version values as select criteria. As the object
>> has been removed the update will return 0 updated objects and
>> hibernate will throw the stale-object exception. So to solve this you
>> should set the id/version of the object to zero (between step 6 and
>> 7). If the object does not have an excplicit id/version eattribute
>> then you should call the IdentifierCacheHandler methods (check the
>> interface to see what method to call).
>> You could say the hibernate resource should set the id/version to
>> null/zero for new objects. However, as the resource can be filled with
>> queries and does not correspond to a xml resource it is not clear if a
>> new object in the resource is really a new object in the database.
>>
>> Can you try if the above helps?
>>
>> Regarding when it is a reference, this exception I do not yet
>> understand. I understand what it means but I do not understand why it
>> occurs.
>>
>> Can you make a testcase (or a testmodel with pseudo code) to reproduce
>> this and enter a bugzilla for it? Then I can check it.in more detail.
>>
>> gr. Martin
>>
>> Matt Biggs wrote:
>>> Hi Martin,
>>>
>>> I'm having a bit of a problem with my resource when attempting to save.
>>>
>>> Pressume my model consists of ClassA which contains a collection of
>>> ClassB.
>>>
>>>
>>> 1. Create/Load a resource with a ClassA object in it.
>>> 2. Save resource. Ok
>>> 3. Add a new instance of ClassB to ClassA.
>>> 4. Save resource. Ok
>>> 5. Undo command stack (removing ClassB).
>>> 6. Save resource. Ok
>>> 7. Redo command stack (re-adding ClassB).
>>> 8. Save resource. FAIL.
>>>
>>> Depending on if the relationship is a containment one or not, i seem
>>> to get one of two exceptions.
>>>
>>> Containment gives me:
>>>
>>> org.hibernate.StaleObjectStateException: Row was updated or deleted
>>> by another transaction (or unsaved-value mapping was incorrect):
>>> [ClassB#1]
>>>
>>> Reference gives me:
>>>
>>> org.hibernate.HibernateException: Found two representations of same
>>> collection: ClassA.classb
>>>
>>>
>>> Is this something to do with cascading?
>>>
>>> cheers
>>>
>>> Matt
>>
>>


--

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: [Teneo] Undo / Redo resource save issue [message #468022 is a reply to message #465358] Mon, 03 August 2009 16:25 Go to previous message
Matt Biggs is currently offline Matt BiggsFriend
Messages: 71
Registered: July 2009
Member
Hi Martin,

I think that would be a good solution then if that is how EMF does it.

Thats ok taking a week or so, i think you do a fantastic job responding
and releasing new features / bug fixes as quickly as you do. Maybe you
should take a holiday!

Matt

Martin Taal wrote:
> Hi Matt,
> I saw it.
>
> I can make the resource smarter to assume that objects added to the
> resource are always new. This is also how EMF looks at it.
>
> I am quite busy at the moment, so it will take a week or so before I can
> spend time on this I am afraid.
>
> In the meantime it should not be too difficult to extend the hibernate
> resource with your own implementation which takes care of nulling the
> ids/versions of new objects in the resources. The new objects are stored
> in a separate arraylist in the resource.
>
> gr. Martin
>
> Matt Biggs wrote:
>> Martin,
>>
>> The problem with changing the ID of the object is that its not always
>> easy to get to the model object.
>>
>> I was simply calling commandstack.undo() etc to undo / redo the model.
>>
>> As such in order to find the object i now have to walk the command
>> stacks redo command, looping through all child commands etc searching
>> for an AddCommand and then call the IdentifierCacheHandler's setId
>> method on its affected objects. I eventually managed to do this but
>> then ran into the 2nd exception i was receiving. So i'm still not sure
>> if that solves the problem.
>>
>> I've knocked together a rather hacky :p testcase and model to
>> reproduce the issue and attached it to bug 285372.
>>
>> Cheers
>>
>> Matt
>>
>>
>>
>> Martin Taal wrote:
>>> Hi Matt,
>>> For the containment what fails is that probably ClassB still has its
>>> id/version set. So when resaving the instance (step 8) Hibernate
>>> will try to do an update instead of a save. Hibernate does an update
>>> with select and checks the count of the updated objects. The select
>>> contains the id and version values as select criteria. As the object
>>> has been removed the update will return 0 updated objects and
>>> hibernate will throw the stale-object exception. So to solve this you
>>> should set the id/version of the object to zero (between step 6 and
>>> 7). If the object does not have an excplicit id/version eattribute
>>> then you should call the IdentifierCacheHandler methods (check the
>>> interface to see what method to call).
>>> You could say the hibernate resource should set the id/version to
>>> null/zero for new objects. However, as the resource can be filled
>>> with queries and does not correspond to a xml resource it is not
>>> clear if a new object in the resource is really a new object in the
>>> database.
>>>
>>> Can you try if the above helps?
>>>
>>> Regarding when it is a reference, this exception I do not yet
>>> understand. I understand what it means but I do not understand why it
>>> occurs.
>>>
>>> Can you make a testcase (or a testmodel with pseudo code) to
>>> reproduce this and enter a bugzilla for it? Then I can check it.in
>>> more detail.
>>>
>>> gr. Martin
>>>
>>> Matt Biggs wrote:
>>>> Hi Martin,
>>>>
>>>> I'm having a bit of a problem with my resource when attempting to save.
>>>>
>>>> Pressume my model consists of ClassA which contains a collection of
>>>> ClassB.
>>>>
>>>>
>>>> 1. Create/Load a resource with a ClassA object in it.
>>>> 2. Save resource. Ok
>>>> 3. Add a new instance of ClassB to ClassA.
>>>> 4. Save resource. Ok
>>>> 5. Undo command stack (removing ClassB).
>>>> 6. Save resource. Ok
>>>> 7. Redo command stack (re-adding ClassB).
>>>> 8. Save resource. FAIL.
>>>>
>>>> Depending on if the relationship is a containment one or not, i seem
>>>> to get one of two exceptions.
>>>>
>>>> Containment gives me:
>>>>
>>>> org.hibernate.StaleObjectStateException: Row was updated or deleted
>>>> by another transaction (or unsaved-value mapping was incorrect):
>>>> [ClassB#1]
>>>>
>>>> Reference gives me:
>>>>
>>>> org.hibernate.HibernateException: Found two representations of same
>>>> collection: ClassA.classb
>>>>
>>>>
>>>> Is this something to do with cascading?
>>>>
>>>> cheers
>>>>
>>>> Matt
>>>
>>>
>
>
Previous Topic:Customize code generation.
Next Topic:How to invoke the code generation programmatically
Goto Forum:
  


Current Time: Thu Dec 12 09:29:55 GMT 2019

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

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

Back to the top