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 |
J. Michael Dean, M.D. 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 |
Martin Taal 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 |
J. Michael Dean, M.D. 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 |
Martin Taal 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
|
|
|
Goto Forum:
Current Time: Sat Oct 19 15:54:14 GMT 2024
Powered by FUDForum. Page generated in 0.03416 seconds
|