Created
October 4, 2017 14:47
-
-
Save BenArunski/405ff4f65cd0aadb114afeb5f8889b0d to your computer and use it in GitHub Desktop.
Equals / Hashcode for lookup table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.ne.state.nsc.npacs.businessobject; | |
import org.apache.commons.lang.StringUtils; | |
import org.hibernate.annotations.Fetch; | |
import org.hibernate.annotations.FetchMode; | |
import us.ne.state.nsc.npacs.lookup.VictimizationTypeLookup; | |
import javax.persistence.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
@Entity | |
@Table(name = "victim") | |
public class Victim extends Npacs { | |
private static final long serialVersionUID = 1L; | |
private Long victimId; | |
private List<VictimizationTypeLookup> victimizationTypeLookups = new ArrayList<>(); | |
public Victim() { | |
} | |
@Id | |
@Column(name = "pk_Victim_Id") | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
public Long getVictimId() { | |
return victimId; | |
} | |
public void setVictimId(Long victimId) { | |
this.victimId = victimId; | |
} | |
@OneToMany(fetch = FetchType.EAGER) | |
@Fetch(FetchMode.SELECT) | |
@JoinTable(name = "victim_Victimization_Types", | |
joinColumns = { @JoinColumn(name = "fk_Victim_Id") }, | |
inverseJoinColumns = { @JoinColumn(name = "fk_Victimization_Type_Cd") }) | |
public List<VictimizationTypeLookup> getVictimizationTypeLookups() { | |
return victimizationTypeLookups; | |
} | |
public void setVictimizationTypeLookups(List<VictimizationTypeLookup> victimizationTypeLookups) { | |
this.victimizationTypeLookups = victimizationTypeLookups; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.ne.state.nsc.npacs.lookup; | |
import org.hibernate.annotations.*; | |
import org.hibernate.annotations.Cache; | |
import org.springframework.transaction.annotation.Transactional; | |
import us.ne.state.nsc.npacs.constants.NpacsConstants; | |
import javax.persistence.*; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
import java.util.Objects; | |
@Entity | |
@Table(name = "lk_Victimization_Type") | |
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |
public class VictimizationTypeLookup extends NpacsLookup { | |
private static final long serialVersionUID = 1L; | |
public VictimizationTypeLookup() { | |
super(); | |
} | |
public VictimizationTypeLookup(Integer lookupCd, String description) { | |
super(lookupCd, description); | |
} | |
@Id | |
@Column(name = "pk_Victimization_Type_Cd") | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
@Override | |
public Integer getLookupCd() { | |
return lookupCd; | |
} | |
@Column(name = "victimization_Type_Descr") | |
public String getDescription() { | |
return description; | |
} | |
@Override | |
public boolean equals(Object object) { | |
return (object instanceof VictimizationTypeLookup) && (lookupCd != null) | |
? lookupCd.equals(((VictimizationTypeLookup) object).lookupCd) | |
: (object == this); | |
} | |
@Override | |
public int hashCode() { | |
return (lookupCd != null) | |
? (VictimizationTypeLookup.class.hashCode() + lookupCd.hashCode()) | |
: super.hashCode(); | |
} | |
@Transient | |
public boolean isOther() { | |
return Objects.equals(NpacsConstants.VICTIMIZATION_TYPE_OTHER, lookupCd); | |
} | |
@Transient | |
public boolean isHateCrime() { | |
return Objects.equals(NpacsConstants.VICTIMIZATION_TYPE_HATE_CRIME, lookupCd); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment