I have a class called NodeTypeJPA-enabled using SQL Server database.
Nothing special, no relationship, just some fields. There are even more of them, but to simplify, I omit them:
@Entity
@Table(name="node_type")
@NamedQuery(name="NodeType.findAll", query="SELECT n FROM NodeType n")
public class NodeType implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
public NodeType() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
When I started the application, I read them and put them in HashMap, taking the property nameas a key to make it easier to find it later.
There are currently five items in the database.
id name maxNoExits mandatoryExits defaultExits
==
1 NTYPE_HUP 0 NodeHangup
2 NTYPE_ANN 1 NodeAnnounce
3 NTYPE_SLP 1 NodeWait
4 NTYPE_XFR 0 NodeTransfer
5 NTYPE_TBR 32 NodeTimebased
A little later, and I don’t know exactly where this happens, several instances for each element suddenly exist (there are currently three instances per element)
Example. In the application, I have an instance of NodeType with values
1 NTYPE_HUP 0 NodeHangup
The eclipse debugger tells me that:
- , ,
map.get nullNodeType 15- , .
- , .
id . getHash() , equals() true, ?
, ! - , ?
JPA ( ?), , @Id. , createQuery, . ?
, , .
, - .
: , , , 15 , JPA . , , .
Edit2: hashCode() ( return this.id;) equals() (return this.id == other.id;)
15 . , , . . , - .