I have a @OneToMany Collection (EstablishmentBins) in my POJO (Establishment), mapped as a Set. I've tried using LinkedHashSet and TreeSet, no go, Hibernate says I can't. Ok, fair enough.
But since it is a plain old Set there is no order. And I need some order. So I changed my EstablishmentBin POJO so it implements Comparable and made a compareTo() method. That's when the problems started. When loading an Establishment in EstablishmentDaoHibernate, If I futz with EstablishmentBins - for example cast it to a TreeSet and do an establishment.setEstablishmentBins(establishmentBinsTreeSet), Hibernate complains saying: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance I also tried: 1. Casting the Set to a TreeSet, calling clear() on the Set and then calling addAll(TreeSet). This doesn't work because at the end of the day, the POJO still has a Set, so any ordering I do is lost. 2. Making a private method, orderBins(TreeSet) in Establishment that either does the stuff from #1 (clear(), addAll(TreeSet)) or from above (this.setEstablishmentBins(establishmentBinsTreeSet)). Neither one works. The first one does nothing, the second fails with the same Hibernate error. So I moved the setEstablishmentBins(establishmentBinsTreeSet) call up into the EstablishmentFormController. Annoying, and probably not a Best Practice. But it works. I am not sure why it works in a Controller and not a Dao, but there it is. But I have another problem - I sometimes load the Establishment from Ajax, and I need the EstablishmentBins to be ordered there as well. But I have no Controller, I call the Manager/DAO directly. So it seems I *need* to put the code for ordering the EstablishmentBins in the DAO, at least for this call. How the heck can I do this without Hibernate getting cross with me? Bob -- View this message in context: http://www.nabble.com/Hibernate-madness---how-to-order-a-Set-tp20604234s2369p20604234.html Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
