Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Equality, hashcodes, EMF and Hibernate
Equality, hashcodes, EMF and Hibernate [message #1040657] Sat, 13 April 2013 20:09 Go to next message
J. Michael Dean, M.D. is currently offline J. Michael Dean, M.D.
Messages: 216
Registered: July 2009
Senior Member
I KNOW that this has been addressed before somewhere, but remain at an
impasse. EMF framework depends on user not overriding the
equal/hashCode methods of objects, and Hibernate encourages overriding
these methods. The main purpose from Hibernate standpoint is assuring
that Java equality not override SQL record equality.

In EMF model, I have an object (Patient) that contains clinical
decisions made about the patient (Decisions). I do not want duplicate
decisions in my database, and these are defined as decisions with the
same attribute A and attribute B.

In my eCore model I have added attributes A and B to the EKeys property
of the relation between Patient and Decisions. But I can add objects
all day long and there is no error or prevention.

I really appreciate your help. I am a newbie to this, but have tried
hard to find the answer.

- Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040780 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040784 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040788 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040792 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040796 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040800 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040804 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1040809 is a reply to message #1040657] Sun, 14 April 2013 01:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Mike,

You can use Diagnostician.INSTANCE to validate your instances. Of
course even if you could override equals, there would be nothing to
prevent logic that added a Decision and then changed the A and B
attribute values to cause a duplicate. I.e., this isn't a constraint
you can generally expect to be always fail fast enforceable so better to
assume you need to do a validity check at some point, i.e., before saving.


On 14/04/2013 2:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an
> impasse. EMF framework depends on user not overriding the
> equal/hashCode methods of objects, and Hibernate encourages overriding
> these methods. The main purpose from Hibernate standpoint is assuring
> that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical
> decisions made about the patient (Decisions). I do not want duplicate
> decisions in my database, and these are defined as decisions with the
> same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys
> property of the relation between Patient and Decisions. But I can add
> objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried
> hard to find the answer.
>
> - Mike
Re: Equality, hashcodes, EMF and Hibernate [message #1041211 is a reply to message #1040657] Sun, 14 April 2013 16:21 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5301
Registered: July 2009
Senior Member
Hi Michael,
EKeys are not transferred to the hibernate mapping. You can define/use the jpa unique constraint annotation for this, so
the unique constraints are enforced by the model then.
I would only override the equals/hashcode methods if you have a direct need for that.

gr. Martin

On 04/14/2013 02:09 AM, J. Michael Dean wrote:
> I KNOW that this has been addressed before somewhere, but remain at an impasse. EMF framework depends on user not
> overriding the equal/hashCode methods of objects, and Hibernate encourages overriding these methods. The main purpose
> from Hibernate standpoint is assuring that Java equality not override SQL record equality.
>
> In EMF model, I have an object (Patient) that contains clinical decisions made about the patient (Decisions). I do not
> want duplicate decisions in my database, and these are defined as decisions with the same attribute A and attribute B.
>
> In my eCore model I have added attributes A and B to the EKeys property of the relation between Patient and Decisions.
> But I can add objects all day long and there is no error or prevention.
>
> I really appreciate your help. I am a newbie to this, but have tried hard to find the answer.
>
> - 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:[Resolve][Teneo] - Howto copy EMF model from one database to another one
Next Topic:Annotation to cause package import
Goto Forum:
  


Current Time: Mon Apr 21 08:53:05 EDT 2014

Powered by FUDForum. Page generated in 0.01889 seconds