Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Xcore] Annotating uniqueness constraints (Newbie)
[Xcore] Annotating uniqueness constraints (Newbie) [message #1219583] Wed, 04 December 2013 18:11 Go to next message
J. Michael Dean, M.D. is currently offline J. Michael Dean, M.D.Friend
Messages: 218
Registered: July 2009
Senior Member
I have built an Xcore EMF model and use Teneo to persist. However, I
need to have uniqueness constraints - I have looked through the lists
but not found the answer.

For example, I have Person objects that include a last and first name,
and a status (current or past, for example). I want a constraint that
the combination of the first and last name must be unique.

With the default Xcore driven EMF code for my objects, and using MySQL,
if I rerun my test application, records keep getting added to the
database.

I have seen uniqueness attribute and annotations on individual columns,
but mostly in the XML files. I am hoping there is a way to express
these constraints using Xcore since it is much more intelligible.

Thanks.

- Mike
Re: [Xcore] Annotating uniqueness constraints (Newbie) [message #1219722 is a reply to message #1219583] Thu, 05 December 2013 14:57 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mike,
In Teneo JPA Annotations can be entered/defined as EAnnotations in a model. I don't know xcore really, but maybe you can
define/enter eAnnotations also in xCore and use that to define these JPA annotations?

gr. Martin

On 12/04/2013 07:11 PM, J. Michael Dean wrote:
> I have built an Xcore EMF model and use Teneo to persist. However, I need to have uniqueness constraints - I have
> looked through the lists but not found the answer.
>
> For example, I have Person objects that include a last and first name, and a status (current or past, for example). I
> want a constraint that the combination of the first and last name must be unique.
>
> With the default Xcore driven EMF code for my objects, and using MySQL, if I rerun my test application, records keep
> getting added to the database.
>
> I have seen uniqueness attribute and annotations on individual columns, but mostly in the XML files. I am hoping there
> is a way to express these constraints using Xcore since it is much more intelligible.
>
> Thanks.
>
> - Mike


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Xcore] Annotating uniqueness constraints (Newbie) [message #1219816 is a reply to message #1219722] Thu, 05 December 2013 22:57 Go to previous messageGo to next message
J. Michael Dean, M.D. is currently offline J. Michael Dean, M.D.Friend
Messages: 218
Registered: July 2009
Senior Member
Martin - I had tried to insert the following as an annotation (I
preceded this with annotation "teneo.jpa" as TeneoJpa):

@TeneoJpa(appinfo="@Table(uniqueConstraints
{@UniqueConstraint(columnNames={"LASTNAME" "FIRSTNAME" "STATUS"})})")

However, this results in massive error statements. Clearly not the
right syntax. The statements below are fine and function correctly. so
myh error is in the appinfo portion of the annotation.

@TeneoJpa(appinfo="@Basic(optional=false) @Column(name=LASTNAME)")
String lastName = ""

My main problem is knowing if an object already exists (I can guard the
database with code). If someone tries to enter a duplicate person, my
check for existence works fine with objects if I write my own hash and
equals contracts, but since EMF depends on not messing with the hash and
equals definitions, this is problematic.

Thanks for your help.

- Mike

On 12/5/13, 7:57 AM, Martin Taal wrote:
> Hi Mike,
> In Teneo JPA Annotations can be entered/defined as EAnnotations in a
> model. I don't know xcore really, but maybe you can define/enter
> eAnnotations also in xCore and use that to define these JPA annotations?
>
> gr. Martin
>
> On 12/04/2013 07:11 PM, J. Michael Dean wrote:
>> I have built an Xcore EMF model and use Teneo to persist. However, I
>> need to have uniqueness constraints - I have
>> looked through the lists but not found the answer.
>>
>> For example, I have Person objects that include a last and first name,
>> and a status (current or past, for example). I
>> want a constraint that the combination of the first and last name must
>> be unique.
>>
>> With the default Xcore driven EMF code for my objects, and using
>> MySQL, if I rerun my test application, records keep
>> getting added to the database.
>>
>> I have seen uniqueness attribute and annotations on individual
>> columns, but mostly in the XML files. I am hoping there
>> is a way to express these constraints using Xcore since it is much
>> more intelligible.
>>
>> Thanks.
>>
>> - Mike
>
>
Re: [Xcore] Annotating uniqueness constraints (Newbie) [message #1219984 is a reply to message #1219816] Sun, 08 December 2013 10:31 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mike,
Took some more time as I thought the error was related to the xcore notation.

But taking a look at your example afaics the JPA annotation does not have the correct format. It should be something like:
@Table(uniqueConstraints=@UniqueConstraint(columnNames={"LASTNAME", "FIRSTNAME","STATUS"}))

I think there is much documentation on the net on JPA, so it should be easy to find more specific information.

gr. Martin

On 12/05/2013 11:57 PM, J. Michael Dean wrote:
> Martin - I had tried to insert the following as an annotation (I preceded this with annotation "teneo.jpa" as TeneoJpa):
>
> @TeneoJpa(appinfo="@Table(uniqueConstraints {@UniqueConstraint(columnNames={"LASTNAME" "FIRSTNAME" "STATUS"})})")
>
> However, this results in massive error statements. Clearly not the right syntax. The statements below are fine and
> function correctly. so myh error is in the appinfo portion of the annotation.
>
> @TeneoJpa(appinfo="@Basic(optional=false) @Column(name=LASTNAME)")
> String lastName = ""
>
> My main problem is knowing if an object already exists (I can guard the database with code). If someone tries to enter
> a duplicate person, my check for existence works fine with objects if I write my own hash and equals contracts, but
> since EMF depends on not messing with the hash and equals definitions, this is problematic.
>
> Thanks for your help.
>
> - Mike
>
> On 12/5/13, 7:57 AM, Martin Taal wrote:
>> Hi Mike,
>> In Teneo JPA Annotations can be entered/defined as EAnnotations in a
>> model. I don't know xcore really, but maybe you can define/enter
>> eAnnotations also in xCore and use that to define these JPA annotations?
>>
>> gr. Martin
>>
>> On 12/04/2013 07:11 PM, J. Michael Dean wrote:
>>> I have built an Xcore EMF model and use Teneo to persist. However, I
>>> need to have uniqueness constraints - I have
>>> looked through the lists but not found the answer.
>>>
>>> For example, I have Person objects that include a last and first name,
>>> and a status (current or past, for example). I
>>> want a constraint that the combination of the first and last name must
>>> be unique.
>>>
>>> With the default Xcore driven EMF code for my objects, and using
>>> MySQL, if I rerun my test application, records keep
>>> getting added to the database.
>>>
>>> I have seen uniqueness attribute and annotations on individual
>>> columns, but mostly in the XML files. I am hoping there
>>> is a way to express these constraints using Xcore since it is much
>>> more intelligible.
>>>
>>> Thanks.
>>>
>>> - Mike
>>
>>
>


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:EMFClient .. very long startup of eclipse after ECP installation
Next Topic:[Texo] Multiple "genmodel"
Goto Forum:
  


Current Time: Thu Apr 25 15:41:34 GMT 2024

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

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

Back to the top