JPA entity, identify Business key -


lets i'm writing jpa entity. simple one. has 3 properties.

public class menuitem {     @id     @generatedvalue     private long menuitemid;      @column(nullable = false)     private string name;      @column(nullable = false)     private type type;      @onetoone(cascade = {cascadetype.all})     @joincolumn(name = "colorid")     private color color; } 

now, lets need override equals/hashcode methods. according suggestion implementing equals() , hashcode() have use sort of "business key equality". have doubts, should consider "business" key here. have properties except of id, or color can excluded it. seems unclear me. thankful if can explain more on topic.

the last statement in reference pure gold:

note business key not have solid database primary key candidate. immutable or unique properties candidates business key.

so in case name , type candidates. assuming type immutable object (you still away without might experience hard detect bugs).

if put unique constraint on color consider in equals / hashcode method also.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -