Clay wrote:
I've got a situation where I'd like to store objects of different types (strings, numbers, dates, booleans, etc) in the same table, with a single insert/retrieval point ("getValue()?) on the same mapped class.
I don't really want to use a byte array, since I'd prefer if these values, once stored in the database, were human readable (unless it's a complex object of some sort).
If you want to store all those types in one table (and presumably in one field), then the only way I can think of is to store them in a string column. However, string/varchar is not very efficient when it comes to storing anything that isn't a string.
A different option would be to use inheritance, and map different types to different tables. Perhaps a parent class StoredObject, with method "Object getValue()". Subclasses can override getValue(). Consider a subclass StoredBoolean, with method "Boolean getValue()".
Using this approach, you could retrieve a list of StoredObjects, and each call of getValue() would return the type used by the method in the subclass. If this sounds like a good option for you, read up on
Hibernate's inheritance capabilities.