Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Unique ID Validation
Unique ID Validation [message #416153] Fri, 18 January 2008 19:25 Go to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
I don't understand why I get unique id validation errors for my models.
I have designated an attribute (name) as an ID for a class (A) in my metamodel.
The metamodel allows instances of A to be contained in another class (B).
I've created a model like:
B::b1
A::a1 (name="foo")
B::b2
A::a2 (name="foo")

When I validate this model, I get errors like
"The ID 'foo' of 'A' collides with that of 'A foo'"

I thought the uniqueness was only required within the container. Working
with the debugger, I see that ResourceImpl.getEObjectByID(String) is
doing the work and it checks *all* the objects, not just the immediate
containers for a1 and a2.

What am I missing?

Thanks,
Mike Gering
Re: Unique ID Validation [message #416155 is a reply to message #416153] Fri, 18 January 2008 19:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mike,

Comments below.

Mike Gering wrote:
> I don't understand why I get unique id validation errors for my models.
Because they aren't unique! :-P
> I have designated an attribute (name) as an ID for a class (A) in my
> metamodel.
> The metamodel allows instances of A to be contained in another class (B).
> I've created a model like:
> B::b1
> A::a1 (name="foo")
> B::b2
> A::a2 (name="foo")
>
> When I validate this model, I get errors like
> "The ID 'foo' of 'A' collides with that of 'A foo'"
IDs must be unique in the entire containing resources across all object
types.
>
> I thought the uniqueness was only required within the container.
Nope. It's just like XML Schema's xsd:id type. A value of that type
must be unique within the document.
> Working
> with the debugger, I see that ResourceImpl.getEObjectByID(String) is
> doing the work and it checks *all* the objects, not just the immediate
> containers for a1 and a2.
Yep.
>
> What am I missing?
You're missing the wonderful new feature EReference.eKeys. On any
EReference (though it's most useful for containment references) you can
specify a subset of the referenced EClass' EAttributes as uniquely
identifying a referenced instance among all the other instances in that
same reference. So "name" is an eKey with regard to the EReference by
which a B contains an A. When you serialize, you'll see instead of
using /@a.<index> it will use /@a[name='foo'] to refer to the object.
And then when you validate it will only complain if any one B contains
more than one A with the same name value.
>
> Thanks,
> Mike Gering


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Unique ID Validation [message #416156 is a reply to message #416155] Fri, 18 January 2008 19:58 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Thanks, Ed. Oh how I wish I could move up! We'll be stuck on 2.2 for
some time yet :-(

Mike Gering
Re: Unique ID Validation [message #416159 is a reply to message #416156] Fri, 18 January 2008 20:33 Go to previous message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Argh! All my work for migrating models is for naught. I had
to change some attributes to ID=false which prevents the old
models from even loading -- the reference format for those attributes
has changed.

Mike
Previous Topic:Adding Structured editor thow exception in generated editor code.
Next Topic:many references: navigating to values
Goto Forum:
  


Current Time: Fri Apr 26 13:17:52 GMT 2024

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

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

Back to the top