Hibernate version:3
I've studied up but can't seem to find a way to deal with this (possibly unorthodox) situation:
I have a mySQL database that stores 'text elements' which is to say various and sundry items of text which are related to other entities (a simple example would be model #, headline, multiple bullet copy points etc. for a product)
Anyway, there are multiple text elements (rows of the text table) related to a given product. They are distinguished from one another by a 'type' field in the text table. (So all bullets have type = "bullet" in the table etc. etc.)
THE QUESTION:
I can easily map a collection of bullets, for example, to my Product class using:
Code:
<list name="bullets"
table="text"
where="type = 'bullet'">
...
</list>
which works quite well.
BUT
How can I do the same thing for a SINGLE value? (How can I do the equivalent of adding a WHERE condition to a normal single property - not a collection?)
as in:
Code:
<property name="modelNumber" where="type = 'modelNumber'"..... />
Which (obviously) won't work, but it illustrates what I'm trying to do.
Is there a way to accomplish this?
EXTRA INFO:
Obviously, a 'list' mapping would be better prepared for possibilities like MULTIPLE 'modelNumber' types that would match the where condition, but I'd like my code to assume that that will never happen with certain types (hopefully by the mapping simply ignoring any extra values) because the UI will never allow the user to create multiples of certain types.
If this situation is referenced in any book or documentation I'm not finding it. I'm thinking there's probably a way to accomplish this but my understanding of Hibernate isn't deep enough to see the solution yet.
Any help or ideas would be greatly appreciated!
Eric