title: Mapping multiple-row per item objects in Hibernate
body: <p>I'm encountering somewhat of an, uh, unorthodox design and I'm not quite sure how to handle it. The table I'm trying to map looks like:</p>
  
  <pre><code>TABLE example {
      ID INT,
      CATEGORY VARCHAR,
      PROPERTY VARCHAR,
      VALUE VARCHAR);
  </code></pre>
  
  <p>A single id can have several rows (obviously, not a primary key). As an example, it could look like:</p>
  
  <pre><code># ID  CATEGORY     PROPERTY VALUE
    1   general_info name     order 1
    1   general_info date     1/1/2009
    ...
  </code></pre>
  
  <p>Every ID might have several different categories for it. Property names are unique for any given (id, category) combination.</p>
  
  <p>(EDIT) The ID field is a foreign key to objects in a different table. I need to be able to get from these objects to the various properties stored in this table, using only the ID field. If a composite key is the way to go, how do I then link them?</p>
  
  <p>(EDIT2) I also think the detail you're missing here is that all the data with the same ID in column one conceptually belongs to the same object. I don't want a separate instance for every (ID,CATEGORY) combination.</p>
  
  <p>Obviously, this isn't very normalized. Worst case scenario, I set up some extra tables that are normalized and copy everything over, but I was wondering if anyone could suggest a sensible way to get this information into hibernate backed objects directly? If necessary in some sort of bag of String properties.</p>
  
  <p>I'm using hibernate-annotations btw.</p>