Skip to main content


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] Sun, 14 April 2013 00:09 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 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 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040784 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040788 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040792 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040796 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040800 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040804 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1040809 is a reply to message #1040657] Sun, 14 April 2013 05:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Equality, hashcodes, EMF and Hibernate [message #1041211 is a reply to message #1040657] Sun, 14 April 2013 20:21 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
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: Wed Apr 24 19:10:46 GMT 2024

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

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

Back to the top