How to implement a canonicalizing mapping in Java?
问题 I am currently rolling my own little ORM, and find myself faced with the task of creating a canonicalizing mapping in order to prevent loading the same entity from the database more than once. My current approach is to use a HashMap<Object, WeakReference<Object>> . The key is the primary key of the mapped database-entity (an ArrayList<Object> if it is a composite key), and the values are WeakReference<Object> . My main problem is how to clean the map up? When an object is not used any more,