[Mdarad-toolbox-devs] Comparator modifications
Brought to you by:
erifr
|
From: <fra...@po...> - 2006-05-08 19:37:40
|
Hi, I made some important modifications to the way the entity class is generated. The entity classes do not implement the Comparable interface anymore. Instead, I have generated an EntityComparator on the side. Now for associations inside an entity, they are now stored in a: new TreeSet(<comparatorClass>) rather than in a simple TreeSet. I had some regression problems implementing this but I think I fixed them all. Just in case though, if you get a ClassCastException in the Hibernate StoredSet class, keep in mind that it is probably because you are trying to save a list, set or collection that is not a SortedSet. This means that you should not do: Collection collection = new HashSet(); product.setItems(collection); but rather: Collection collection = new TreeSet(ItemComparator); product.setItems(collection); You should almost never have to set the collection though. The proper way to do this would be to iterate in the collection and to add them individually or: Collection collection; ... product.getItems().clear(); product.getItems().addAll(collection); If you have any questions let me know. |