I have an object so that
class MyObj{
public long id_1;
...
}
My HBM (hibernate mapping file) tells that this id_1 is my Id. Now what i want to do is to cache this entity in HashMap so that HashMap<MyObj, NestObj>
i.e., MyObj
will become the key for the hashMap.
Now the question that I wanted to ask
I want to make sure that even though i have saved the whole object as the key, I want to keep object retrieval/storing in the hashmap based on the MyObj.id_1
value. The easiest way i can do so is to after retrieving all objects, I have to do a for loop to add them in a map as Map <Integer, MyObj>
but in that case i would have maintain two maps (one for MyObj
and other for NestedObj
) which i want to avoid.
How can i dictate my HashMap to use MyObj.id_1
column to use as comparator, hash etc. Shall i override hash
and equal
function ? But if i do so, would it affect hibnerate comparison while storing/retrieving entities ?