Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Setting an object as 'new' in Teneo/Hibernate
[Teneo] Setting an object as 'new' in Teneo/Hibernate [message #80083] Tue, 17 April 2007 14:46 Go to next message
Eclipse UserFriend
Martin,

In order to support 'undo' for delete operations in my editor I need to be
able to re-save an object that has been deleted from the database. If a
user deletes an object, does a save, the object is deleted fine. However,
if the user then subsequently 'undoes' the delete the 'undo' code re-adds
the object. The problem is that the next save fails with a message that
the row has been deleted or modified by another transaction.

I suspect that the object saved in memory has a signature that makes it
appear as though it exists in the database. I think I need to make the
object appear as a new object so that it can be added to the database as a
new row.

Is this possible.??

Thanks,
Mark.
Re: [Teneo] Setting an object as 'new' in Teneo/Hibernate [message #80157 is a reply to message #80083] Tue, 17 April 2007 16:14 Go to previous messageGo to next message
Eclipse UserFriend
Martin,

Or, maybe just a way to query to see if the object is still in the
database, if not I create a copy of the object to store.

Mark.
Re: [Teneo] Setting an object as 'new' in Teneo/Hibernate [message #80171 is a reply to message #80157] Tue, 17 April 2007 16:29 Go to previous messageGo to next message
Eclipse UserFriend
Mark,
You can try to call session.evict(object) and sets its id property to zero (if it is a long) or null
or another sensible not-set value. In this case you need to be sure that the object does not exist
anymore in the db (but it shouldn't because you deleted it).

One thing you have to also consider is that if you undelete an object (save it again after it was
deleted) that also all the objects it refers to have to be undeleted (if they were deleted).

gr. Martin

Mark wrote:
> Martin,
>
> Or, maybe just a way to query to see if the object is still in the
> database, if not I create a copy of the object to store.
>
> Mark.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Setting an object as 'new' in Teneo/Hibernate [message #80219 is a reply to message #80171] Tue, 17 April 2007 18:54 Go to previous messageGo to next message
Eclipse UserFriend
Martin,

How do I set the ID property on my model objects...? The ID is not an
attribute of my objects.

Mark.
Re: [Teneo] Setting an object as 'new' in Teneo/Hibernate [message #80234 is a reply to message #80219] Wed, 18 April 2007 01:32 Go to previous message
Eclipse UserFriend
Mark,
You can try:
IdentifierCacheHandler.setId(yourUndeletedObject, null)
(and do session.evict)

gr. Martin

Mark wrote:
> Martin,
>
> How do I set the ID property on my model objects...? The ID is not an
> attribute of my objects.
>
> Mark.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Setting an object as 'new' in Teneo/Hibernate [message #604815 is a reply to message #80083] Tue, 17 April 2007 16:14 Go to previous message
Eclipse UserFriend
Martin,

Or, maybe just a way to query to see if the object is still in the
database, if not I create a copy of the object to store.

Mark.
Re: [Teneo] Setting an object as 'new' in Teneo/Hibernate [message #604817 is a reply to message #80157] Tue, 17 April 2007 16:29 Go to previous message
Eclipse UserFriend
Mark,
You can try to call session.evict(object) and sets its id property to zero (if it is a long) or null
or another sensible not-set value. In this case you need to be sure that the object does not exist
anymore in the db (but it shouldn't because you deleted it).

One thing you have to also consider is that if you undelete an object (save it again after it was
deleted) that also all the objects it refers to have to be undeleted (if they were deleted).

gr. Martin

Mark wrote:
> Martin,
>
> Or, maybe just a way to query to see if the object is still in the
> database, if not I create a copy of the object to store.
>
> Mark.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Setting an object as 'new' in Teneo/Hibernate [message #604826 is a reply to message #80171] Tue, 17 April 2007 18:54 Go to previous message
Eclipse UserFriend
Martin,

How do I set the ID property on my model objects...? The ID is not an
attribute of my objects.

Mark.
Re: [Teneo] Setting an object as 'new' in Teneo/Hibernate [message #604829 is a reply to message #80219] Wed, 18 April 2007 01:32 Go to previous message
Eclipse UserFriend
Mark,
You can try:
IdentifierCacheHandler.setId(yourUndeletedObject, null)
(and do session.evict)

gr. Martin

Mark wrote:
> Martin,
>
> How do I set the ID property on my model objects...? The ID is not an
> attribute of my objects.
>
> Mark.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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
Previous Topic:[Teneo] Multivalued EAttributes of EDataTypes do not have the correct Hibernate mapping
Next Topic:[Teneo]Cannot create mappings for emf's XMLNamespace model
Goto Forum:
  


Current Time: Sat Jul 19 05:23:12 EDT 2025

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

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

Back to the top