Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » UUID eattribute conflicts in ECoreUtil.copy(Auto-generate a new UUID at using ECoreUtil.copy)
UUID eattribute conflicts in ECoreUtil.copy [message #986346] Tue, 20 November 2012 08:06 Go to next message
Paco Blanco is currently offline Paco Blanco
Messages: 28
Registered: June 2012
Junior Member
Hello,

I am using an EClass with a String EAttribute that relates to an UUID. I do not know if my way to set the UUID value is good but I initialize it in the constructor:
protected Constructor() {
   super();
   setUUID(EcoreUtil.generateUUID());
}

The setUUID is the setter autogenerated by the EMF generator code.

When I do a copy of an element using EcoreUtil.copy(EObject), I want the generated new element has a different UUID because this new element is a different instance. Unluckily, although the contructor sets a new value just generated, the Copier overwrittes the value with the same value of the element to copy.

My first attempt to solve it is to put the changeable property of the EAttribute to false and convert the attribute to a final variable. But I do not know to put the value of the generateUUID() to the attribute: the setter has been deleted (logically) but all types of eSet give me an exception around to impossible change the value of a not changeable feature.

Some solution?

[Updated on: Tue, 20 November 2012 08:21]

Report message to a moderator

Re: UUID eattribute conflicts in ECoreUtil.copy [message #986516 is a reply to message #986346] Tue, 20 November 2012 17:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Paco,

Comments below.

On 20/11/2012 9:06 AM, Paco Blanco wrote:
> Hello,
>
> I am using an EClass with a String EAttribute that relates to an UUID.
> I do not know if my way to set the UUID value is good but I initialize
> it in the constructor:
> protected Constructor() {
> super();
> setUUID(EcoreUtil.generateUUID());
> }
That seems poor... Better to specialize for the getter to compute one
when the current value is null so you don't compute one and then
overwrite it when deserializing.
> The setUUID is the setter autogenerated by the EMF generator code.
>
> When I do a copy of an element using EcoreUtil.copy(EObject), I want
> the new element generated has a different UUID because this new
> element is a different instance. Unluckily, although the contructor
> sets a new value just generated, the Copier overwrittes the value with
> the same value of the element to copy.
Yes, copiers copy everything.
>
> My first attempt to solve it is to put the EAttribute with its
> changeable property to false and convert the attribute to a final
> variable.
You should never modify the generated meta model. You won't be able to
deserialize the values and presumably you want that to work.
> But I do not know to put the value of the generateUUID() to the
> attribute: the setter is deleted (logically) but all types of eSet
> give me an exception around to impossible change the value of a not
> changeable feature.
Because you modified the generated model presumably.
>
> Some solution?
A specialized Copier that knows you don't want certain features copied.
Re: UUID eattribute conflicts in ECoreUtil.copy [message #986673 is a reply to message #986516] Wed, 21 November 2012 10:47 Go to previous messageGo to next message
Paco Blanco is currently offline Paco Blanco
Messages: 28
Registered: June 2012
Junior Member
Thanks for advices
Specialized Copier ignoring my efeatures works without problems
Unluckly, I use CDO as persistent technology and the new eObject just copied sets a null in the UUID column in DB if I move the setUUID(EcoreUtil.generateUUID()) to getter method. I think CDO directly uses emf reflection by eGet and ignores the top getter of the EClass.
Re: UUID eattribute conflicts in ECoreUtil.copy [message #986818 is a reply to message #986673] Wed, 21 November 2012 18:08 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Paco,

There are two different feature delegation patterns, Reflective and
Dynamic. If you use Reflective, the Reflective, the eGet methods should
delete to your specialized getter.

On 21/11/2012 11:47 AM, Paco Blanco wrote:
> Thanks for advices
> Specialized Copier ignoring my efeatures works without problems
> Unluckly, I use CDO as persistent technology and the new eObject just
> copied sets a null in the UUID column in DB if I move the
> setUUID(EcoreUtil.generateUUID()) to getter method. I think CDO
> directly uses emf reflection by eGet and ignores the top getter of the
> EClass.
Previous Topic:Order of @Type and @JoinTable can break hibernate mapping
Next Topic:EcoreUtil.equals for xsd:list type
Goto Forum:
  


Current Time: Tue Sep 30 14:01:49 GMT 2014

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

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