Hibernate version: 2.1
Mapping documents: TBD
Code between sessionFactory.openSession() and session.close(): N/A
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: N/A
Debug level Hibernate log excerpt: N/A
Hi,
I have a class (AttributeSet) that contains a SortedSet
(attributeValues) that contains Strings. The AttributeSet
class allows a Comparator class to be given as a constructor
arg, which results in the underlying attributeValues
using either the natural ordering of the Strings or the
Comparator-dictated ordering. I would very much like to
persist this class. It seems that because the Comparator
may or may not exist, that the "<set .... sort="X"> notation
will not work, so I should use an order-by approach, yes?
I cannot seem to find an example as to how to do this,
exactly -- and I'd also like to make sure that when I eventually
get around to retrieving an instance of this class from the DB
that the same Comparator (if it existed) is still used for future
additions to the set. In theory a SortedSet, when persisted and
retrieved from the DB, would result in a TreeSet with the same
comparator as the original SortedSet -- chapter 6 doesn't
seem to address that issue directly. I could certainly make
the Comparator a property of the AttributeSet class.
Anyway -- to get back to the first of these problems, I apparently
need to make a column in the AttributeSet table that indicates
the ordering of the one-to-many contents of the attributeValues.
So...how am I to "fill in" these values? It is not as though each
individual String stored in attributeValues has a property
by which I can order. Do I need to make another wrapper class
that holds an integer/String, then assign the integers an "index"
each time an add/remove is done?
One other possibility seems to start with a List collection, but
I do have Sets here, so I could use a List internally, then when
anyone inserts perform a manual compare-and-insert step.
I could do that, but given that I am still so new to Hibernate and
have been so confused already (I have not used any sort of
database before either, so that nomenclature is new also), I thought
it best if I asked about how normal people would approach this problem.
Thanks all,
Jennifer Bevan
|