This should be easy to do in Hibernate, but I can't figure it out. I have a SQL table called MEMBER that has, among other fields, these two:
MEMBER_ID (a long integer, primary key)
MEMBER_NAME (a string)
I also have a MEMBER_ATTRIBUTE table with the following fields:
ATTRIBUTE_NAME (a string)
MEMBER_ID (long integer, refers to member_id in my MEMBER table)
Two key pieces of information: The ATTRIBUTE_NAME value in my member_attribute table is *not* a primary key; there are multiple members for any named attribute. i.e. this table might contain records like:
"swimmer", 1
"swimmer", 2
"runner", 1
"runner", 4
The other key piece of information is that a member may have more than one attribute. Using the data shown just above, member #1 is both a "swimmer" and a "runner".
My instincts tell me that I should build a third table listing the unique attribute values. It would have two fields:
ATTRIBUTE_ID
ATTRIBUTE_NAME
My member_attribute table could then be two fields:
ATTRIBUTE_ID
MEMBER_ID
I could then have a Java class called 'memberAttribute' that would have the identifying 'attributeId' field, a String 'attributeName' field, and a HashSet of members that match that attribute.
All well and good, but I can't match this design to a working set of XML maps. Could anyone throw me a bone?
On a related note, I've built a stored procedure that can take, as a String parameter, an attribute, and will return all the fields for the members that match that attribute. The Hibernate documentation mentions the <sql-query> tag, but does not explain (at least not well enough for a beginner like me) how to tag a query's parameters.
Any ideas would be welcome.
_________________ Java - write once, debug everywhere.
|