Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCLConsole Saving Error: The 'no duplicates' constraint is violated
OCLConsole Saving Error: The 'no duplicates' constraint is violated [message #486027] Tue, 15 September 2009 23:58 Go to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
I am getting this error when I try to save an OCL expression to an xmi file.

public void setOCLExpression(OCLExpression<Object> expr) {
// add my expression as the first root, because I already contain
// variables and EPackages defining dynamically-generated types
getContents().add(0, expr);
}

Exception:
"Error Saving OCL Expression, The 'no duplicates' constraint is violated"

Any help is appreciated.

Regards,
Richard Catlin
Re: OCLConsole Saving Error: The 'no duplicates' constraint is violated [message #486051 is a reply to message #486027] Wed, 16 September 2009 05:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Richard

You provide no clues as to what you are saving, so I can do little more
than elaborate the message, which occurs when the same EObject is added
more than once to an EList that enforces unique content.

So for some reason you are adding a duplicate expression; most likely
a singleton value such as (Ocl)Invalid that may have arisen more than once.

You need to investigate waht is duplicated and where each one came from.

When you tell us how to reproduce the problem we may be able to improve
the error message.

Regards

Ed Willink


Richard Catlin wrote:
> I am getting this error when I try to save an OCL expression to an xmi
> file.
>
> public void setOCLExpression(OCLExpression<Object> expr) {
> // add my expression as the first root, because I already contain
> // variables and EPackages defining dynamically-generated types
> getContents().add(0, expr);
> }
>
> Exception:
> "Error Saving OCL Expression, The 'no duplicates' constraint is violated"
>
> Any help is appreciated.
>
> Regards,
> Richard Catlin
>
Re: OCLConsole Saving Error: The 'no duplicates' constraint is violated [message #486153 is a reply to message #486051] Wed, 16 September 2009 14:25 Go to previous messageGo to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
Ed,

Thanks for the response. I should have elaborated.

I have simply created an ecore model, generated the code, and run the
generated editor. I have also included the OCL Interpreter that
Christian wrote.

Within the OCLConsolePage, there is an input window (SourceViewer) and
an output window (Read-only TextViewer).

When I enter a valid OCL expression and hit Enter, the OCL expression is
parsed and evaluated, and the results are outputted in the TextViewer.
There is a button to save the OCL Expression (lastExpression variable)
to the default persistence mechanism, an XMI file. After I select the
file location, the Error dialog pops up. I have tried many expressions
such as:

self.title
self.question->size() > 1

which are valid OCL expressions.

My understanding is that the OCL expression that I enter is parsed into
the AST (OCL is an ecore model), and that this AST structure is
persisted, just like any ecore model.

Thanks for the heads up about an EList's uniqueness constraint.

It is interesting that Christian put this comment in his code:
// add my expression as the first root, because I already contain
// variables and EPackages defining dynamically-generated types
getContents().add(0, expr);

When I debug, it seems that getContents() already has 3 strucutres in
it. Do you know why? Typically when I save an instance of an ecore
model that I have created it is the only strucutre in the file. The EMF
book also says to use this code to do

getContents().add(expr)

I presume that OCL has some special requirements and that is why
there are already 3 structures. Any ideas here?

When I modify the code to
getContents().add(expr)
I don't get the error, but the OCL expression can not be loaded from the
file.

Any help is appreciated.

Regards,
Richard Catlin





On 9/15/2009 10:49 PM, Ed Willink wrote:
> Hi Richard
>
> You provide no clues as to what you are saving, so I can do little more
> than elaborate the message, which occurs when the same EObject is added
> more than once to an EList that enforces unique content.
>
> So for some reason you are adding a duplicate expression; most likely
> a singleton value such as (Ocl)Invalid that may have arisen more than once.
>
> You need to investigate waht is duplicated and where each one came from.
>
> When you tell us how to reproduce the problem we may be able to improve
> the error message.
>
> Regards
>
> Ed Willink
>
>
> Richard Catlin wrote:
>> I am getting this error when I try to save an OCL expression to an xmi
>> file.
>>
>> public void setOCLExpression(OCLExpression<Object> expr) {
>> // add my expression as the first root, because I already contain
>> // variables and EPackages defining dynamically-generated types
>> getContents().add(0, expr);
>> }
>>
>> Exception:
>> "Error Saving OCL Expression, The 'no duplicates' constraint is violated"
>>
>> Any help is appreciated.
>>
>> Regards,
>> Richard Catlin
>>
EXTLibrary Model also throws OCLConsole Saving Error: The 'no duplicates' constraint is violated [message #486223 is a reply to message #486153] Wed, 16 September 2009 19:40 Go to previous messageGo to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
I tried this on the EXTLibrary example and get the same error for simple
OCL expressions.

1. I installed eclipse-modeling-galileo-incubation-win32.zip
2. I start and switch to the Plug-in Development Perspective
3. I switch to the Plugins tab and import as source
org.eclipse.emf.ocl.examples
4. I then Import "Existing Projects into Workspace" for each of the zip
files: interpreter.zip, library.zip, libraryEdit.zip, and
libraryEditor.zip and get four projects that build properly.
5. I run the Editor project, which launches an Eclipse Runtime.
6. I create a new EMF Project, and then create an EXTLibrary Model.
7. In the Editor, I add a Library Child and give it a name.
8. I right-click on the Library Node, and start the OCL Interpreter.
9. In the bottom pane (the SourceViewer), I enter: name and then hit
enter. In the TextViewer pane, I see the Results with the correct
information for the name displayed.
10. I want to save this OCL Expression to an xmi file and click on the
Save button. I select a directory and create a new file name. When I
hit OK, I get the ERROR dialog:
OCLConsole Saving Error: The 'no duplicates' constraint is violated

Am I doing something wrong?

Regards,
Richard Catlin


On 9/16/2009 7:25 AM, Richard Catlin wrote:
> Ed,
>
> Thanks for the response. I should have elaborated.
>
> I have simply created an ecore model, generated the code, and run the
> generated editor. I have also included the OCL Interpreter that
> Christian wrote.
>
> Within the OCLConsolePage, there is an input window (SourceViewer) and
> an output window (Read-only TextViewer).
>
> When I enter a valid OCL expression and hit Enter, the OCL expression is
> parsed and evaluated, and the results are outputted in the TextViewer.
> There is a button to save the OCL Expression (lastExpression variable)
> to the default persistence mechanism, an XMI file. After I select the
> file location, the Error dialog pops up. I have tried many expressions
> such as:
>
> self.title
> self.question->size() > 1
>
> which are valid OCL expressions.
>
> My understanding is that the OCL expression that I enter is parsed into
> the AST (OCL is an ecore model), and that this AST structure is
> persisted, just like any ecore model.
>
> Thanks for the heads up about an EList's uniqueness constraint.
>
> It is interesting that Christian put this comment in his code:
> // add my expression as the first root, because I already contain
> // variables and EPackages defining dynamically-generated types
> getContents().add(0, expr);
>
> When I debug, it seems that getContents() already has 3 strucutres in
> it. Do you know why? Typically when I save an instance of an ecore
> model that I have created it is the only strucutre in the file. The EMF
> book also says to use this code to do
>
> getContents().add(expr)
>
> I presume that OCL has some special requirements and that is why there
> are already 3 structures. Any ideas here?
>
> When I modify the code to
> getContents().add(expr)
> I don't get the error, but the OCL expression can not be loaded from the
> file.
>
> Any help is appreciated.
>
> Regards,
> Richard Catlin
>
>
>
>
>
> On 9/15/2009 10:49 PM, Ed Willink wrote:
>> Hi Richard
>>
>> You provide no clues as to what you are saving, so I can do little
>> more than elaborate the message, which occurs when the same EObject is
>> added
>> more than once to an EList that enforces unique content.
>>
>> So for some reason you are adding a duplicate expression; most likely
>> a singleton value such as (Ocl)Invalid that may have arisen more than
>> once.
>>
>> You need to investigate waht is duplicated and where each one came from.
>>
>> When you tell us how to reproduce the problem we may be able to
>> improve the error message.
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> Richard Catlin wrote:
>>> I am getting this error when I try to save an OCL expression to an
>>> xmi file.
>>>
>>> public void setOCLExpression(OCLExpression<Object> expr) {
>>> // add my expression as the first root, because I already contain
>>> // variables and EPackages defining dynamically-generated types
>>> getContents().add(0, expr);
>>> }
>>>
>>> Exception:
>>> "Error Saving OCL Expression, The 'no duplicates' constraint is
>>> violated"
>>>
>>> Any help is appreciated.
>>>
>>> Regards,
>>> Richard Catlin
>>>
Re: EXTLibrary Model also throws OCLConsole Saving Error: The 'no duplicates' constraint is violated [message #486255 is a reply to message #486223] Wed, 16 September 2009 21:28 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Richard

No you're doing nothing wrong.

Thank you for the clear repro.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=289660 raised.

There is a good chance that deleting the

res.setOCLExpression(parsed);

at line 135 of OCLResource will cure the problem.

---

When OCL is persisted there are a variety of orphan elements. For a
complete OCL model this may just be any collection tyupe declarations.
For a partial model your example needs a self variable. FOr some reason
two (no-duplicate) self variables are persisted.

In general it is a responsibility of the OCL AST consumer to resolve the
orphans. THe OCL interpreter does this by placing them all at the root.
---

Step 4: New->Example->OCL Plugins->OCL Interpreter does this in one hit.

Regards

Ed Willink


Richard Catlin wrote:
> I tried this on the EXTLibrary example and get the same error for simple
> OCL expressions.
>
> 1. I installed eclipse-modeling-galileo-incubation-win32.zip
> 2. I start and switch to the Plug-in Development Perspective
> 3. I switch to the Plugins tab and import as source
> org.eclipse.emf.ocl.examples
> 4. I then Import "Existing Projects into Workspace" for each of the zip
> files: interpreter.zip, library.zip, libraryEdit.zip, and
> libraryEditor.zip and get four projects that build properly.
> 5. I run the Editor project, which launches an Eclipse Runtime.
> 6. I create a new EMF Project, and then create an EXTLibrary Model.
> 7. In the Editor, I add a Library Child and give it a name.
> 8. I right-click on the Library Node, and start the OCL Interpreter.
> 9. In the bottom pane (the SourceViewer), I enter: name and then hit
> enter. In the TextViewer pane, I see the Results with the correct
> information for the name displayed.
> 10. I want to save this OCL Expression to an xmi file and click on the
> Save button. I select a directory and create a new file name. When I
> hit OK, I get the ERROR dialog:
> OCLConsole Saving Error: The 'no duplicates' constraint is violated
>
> Am I doing something wrong?
>
> Regards,
> Richard Catlin
>
>
> On 9/16/2009 7:25 AM, Richard Catlin wrote:
>> Ed,
>>
>> Thanks for the response. I should have elaborated.
>>
>> I have simply created an ecore model, generated the code, and run the
>> generated editor. I have also included the OCL Interpreter that
>> Christian wrote.
>>
>> Within the OCLConsolePage, there is an input window (SourceViewer) and
>> an output window (Read-only TextViewer).
>>
>> When I enter a valid OCL expression and hit Enter, the OCL expression
>> is parsed and evaluated, and the results are outputted in the
>> TextViewer. There is a button to save the OCL Expression
>> (lastExpression variable) to the default persistence mechanism, an XMI
>> file. After I select the file location, the Error dialog pops up. I
>> have tried many expressions such as:
>>
>> self.title
>> self.question->size() > 1
>>
>> which are valid OCL expressions.
>>
>> My understanding is that the OCL expression that I enter is parsed
>> into the AST (OCL is an ecore model), and that this AST structure is
>> persisted, just like any ecore model.
>>
>> Thanks for the heads up about an EList's uniqueness constraint.
>>
>> It is interesting that Christian put this comment in his code:
>> // add my expression as the first root, because I already contain
>> // variables and EPackages defining dynamically-generated types
>> getContents().add(0, expr);
>>
>> When I debug, it seems that getContents() already has 3 strucutres in
>> it. Do you know why? Typically when I save an instance of an ecore
>> model that I have created it is the only strucutre in the file. The
>> EMF book also says to use this code to do
>>
>> getContents().add(expr)
>>
>> I presume that OCL has some special requirements and that is why
>> there are already 3 structures. Any ideas here?
>>
>> When I modify the code to
>> getContents().add(expr)
>> I don't get the error, but the OCL expression can not be loaded from
>> the file.
>>
>> Any help is appreciated.
>>
>> Regards,
>> Richard Catlin
>>
>>
>>
>>
>>
>> On 9/15/2009 10:49 PM, Ed Willink wrote:
>>> Hi Richard
>>>
>>> You provide no clues as to what you are saving, so I can do little
>>> more than elaborate the message, which occurs when the same EObject
>>> is added
>>> more than once to an EList that enforces unique content.
>>>
>>> So for some reason you are adding a duplicate expression; most likely
>>> a singleton value such as (Ocl)Invalid that may have arisen more than
>>> once.
>>>
>>> You need to investigate waht is duplicated and where each one came from.
>>>
>>> When you tell us how to reproduce the problem we may be able to
>>> improve the error message.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>> Richard Catlin wrote:
>>>> I am getting this error when I try to save an OCL expression to an
>>>> xmi file.
>>>>
>>>> public void setOCLExpression(OCLExpression<Object> expr) {
>>>> // add my expression as the first root, because I already contain
>>>> // variables and EPackages defining dynamically-generated types
>>>> getContents().add(0, expr);
>>>> }
>>>>
>>>> Exception:
>>>> "Error Saving OCL Expression, The 'no duplicates' constraint is
>>>> violated"
>>>>
>>>> Any help is appreciated.
>>>>
>>>> Regards,
>>>> Richard Catlin
>>>>
Previous Topic:OCL query to find classes
Next Topic:Query for not all elements of a model
Goto Forum:
  


Current Time: Thu Apr 25 13:44:35 GMT 2024

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

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

Back to the top