Fix race condition when adding new record and calling getId() before it's committed (NullPointerException)
Usage of TreeSet with different record types cause ClassCastException (Comparable interface): use HashSet instead.