My (legacy) data model includes a pair of tables along the lines of
Code:
table Item (
item_id integer,
description varchar
)
table Attribute (
attribute_id integer,
item_id integer,
category varchar,
description varchar
)
The existing code that manipulates those tables exposes the data using the Composite pattern, with a top-level node representing the Item row, a synthetic set of second-level nodes with the category values as their descriptions (the "id" properties of those nodes are ignored), and leaf nodes under each of the categories with the actual descriptions.
How would you map that object model to the tables using Hibernate? It seems like components would almost work, except that a single second-level node can represent more than one row in the Attribute table.
The only approach that's coming to mind right now is to map the Attribute table to a flat collection under the Item class, then provide a method to scan the collection and generate the hierarchy using non-persistent objects that refer back to the persistent ones. Any better ideas?