How Can I make This Algorithm Generic?
<p>I am working on an object cache of CMS objects.  I need to maintain a parent/child relationship between a Product and child objects (Options and Attributes).  The parent (Product) is illustrated in the first code sample.</p>

<p>It is easy enough to do, but I am looking for a way to make the assignment of the child to the parent, as shown in the 2nd code block, generic.</p>

<p>Since all CMS objects extend CMSContent, I can use ProductID.  However, is there a way to make the field (e.g. ProductAttribute) generic so that I can put the algorithm in a method and call the method with a parent and child object to make the attribute assignment?</p>

<p>I know that an ORM framework like Hibernate is appropriate here, but that won't fit since I have a fixed database structure.</p>

<pre><code>public class Product extends CMSContent {
    private List&lt;ProductAttribute&gt; productAttributes;
    private List&lt;ProductOptions&gt; productOptions;

    // getters,setters
}
</code></pre>

<p>Algorithm to match them up.</p>

<pre><code>// attach Product Attributes to Product
for (Product p : listP) {
    Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
    for (ProductAttribute po : listPA) {
        parameters.put("pid", p.getPid());
        parameters.put("ref", po.getRid());

        int i = jdbcTemplate.queryForInt(sqlAttr, parameters);  // select count(*), 1 if matched.

        if (i == 1) {
            p.getProductAttributes().add(po);  // generic field?
        }
    }
}
</code></pre>
