hashCode « Map « JPA Q&A





1. Hibernate/JPA Parent-Child - is it okay for Parent equals()/hashCode() to use the DB Id?    stackoverflow.com

Given the following:

@Entity
public class Parent implements Serializable {
  @Id
  private Long id;
  // mapped ManyToOne below...
  private List<Child> children = new ArrayList<Child>();

  ...

}
Is it a bad ...

2. What is the correct way of overriding hashCode () and equals () methods of persistent entity?    stackoverflow.com

I have a simple class Role:

@Entity
@Table (name = "ROLE")
public class Role implements Serializable {

    @Id
    @GeneratedValue
    private Integer id;
    ...

3. Equal and hashcode in inherited class    stackoverflow.com


In my understanding, the below implementation of equal and hashcode are safe as the correct method in derived class would invoke (instead of parent), even if I call ...

4. JPA : not overriding equals() and hashCode() in the entities?    stackoverflow.com

After reading this article , im bending toward not overriding equals() and hashCode() altogether. In the summary of that article, concerning the no eq/hC at all column, the only consequence ...

5. Implementing equals/hashCode using a referenced ManyToOne entity    stackoverflow.com

Assume we have following JPA Entities:

class Parent {
    @Id
    private Long id;
}

class Child {
    @Id
    private Long id;

  ...

8. Regarding overriding of hashcode() and equals() method in Hibernate.    coderanch.com

Hi.. I am having Activity domain class and fields are like this: private Integer activityID; private String activityName; private Integer type; private Application application; private Project project; private ActivityConfigurable activityConfigurable; private ActivityNonConfigurable activityNonConfigurable; private Status status; private Set activityScripts; activityID is the primary key in database. Can somebody tell me which fields should I use while overriding hashcode() and equals() methods? ...

9. Why do I need to override hashCode() in the @IdClass when using Hibernate    coderanch.com

Hi, Can some one please tell me why I need to override hashCode() in the my @IdClass when using composite primary keys? I do not face any issue when saving and retrieving entities with composite primary keys with out overriding this method. Can someone tell me a scenario where hashCode implementation is a must? Thanks in advance, Amitava





10. Entity with proper equals/hashCode is useless Map key?    forum.hibernate.org

My entities do not "behave" as Map keys. Duplicates are entered with map.put(assetTypeCustomAttribute, value) using the same instance as a key, and map.contains(assetTypeCustomAttribute) always returns false. I really need a second pair of eyes, been struggling with this for a couple of days. Here's how I use an entity named AssetTypeCustomAttribute as a map key: Code: ...