Ivan
Ivan

Reputation: 499

Hibernate duplicate values

I'am studying Hibernate and faced with little problem.

I have a class Item, witch mapped on DB with same columns:

@Entity
class Item {
    private long id;
    private long hash;
    private String name;
    // ... constructors/getters/setters ...
}

Hashes(CRC, Adler, nevermind) generated on programm initialization. They can be duplicated for some reason.

Question is: how to get Map < Long, Item >, were key is hash?

Upvotes: 0

Views: 235

Answers (1)

Peter Š&#225;ly
Peter Š&#225;ly

Reputation: 2933

What for do you need hash column in this example?

  1. Database Id is uniqe, you can use it like hash or generate hash from it
  2. you should anotate id with identity @Id
  3. you should override equals(), hash() functions correctly.

Upvotes: 1

Related Questions