I have 3 tables as follows:
documents
document_tables
tables
A document can have many tables. A table can belong to one and only one document. A document has a collection of tables.
document.hbm.xmlCode:
<bag name="tables" table="document_tables" lazy="false" cascade="save-update">
<key column="document_id" />
<many-to-many column="table_id" unique="true" class="org.aafp.jms.model.AbstractTable" />
</bag>
table.hbm.xmlCode:
<join table="document_tables" inverse="true" optional="true">
<key column="table_id"/>
<many-to-one name="document" column="document_id" not-null="true"/>
</join>
This works great. But I cannot do a mapping that has a subset of the entire collection of tables based on a field that is in the tables table. Is there some way to expose the field I need for the subset criteria. If I didn't have to map it like this with the many-to-many table in the middle I could use the where clause of the bag. I can't do that because I have a similar setup for another entity.
I'm relegated to using something like what follows:
AbstractDocument.javaCode:
public List getSupplementalTables() {
List supplementalTables = new ArrayList();
for (Iterator it = getTables().iterator(); it.hasNext();) {
AbstractTable table = (AbstractTable) it.next();
if (table.isSupplemental()) {
supplementalTables.add(table);
}
}
return supplementalTables;
}
Now, I loop through and spring:bind a supplemental table object property named order to a mvc view.
Code:
<spring:bind path="document.supplementalTables[${count.index}].order">
<input type="text" size="2" maxlength="2" name="${status.expression}" value="${status.value}" /><br/>
</spring:bind>
I'm getting strange results from editing this view.
Any thoughts or help is greatly appreciated.