Updating two-level children in ManyToMany related tables
rlogman Oct 10, 2008 12:10 AMI have had problems updating records of a many to many relationship. I have two main entities: Indicator and Classification. Each classification has a list of ClassificationValue records; and each indicator has a list of classification values. So, the ManyToMany relationship exists between Indicator and ClassificationValue. The model is:
----------- | Indicator | ----------- * | | * --------------------- | ClassificationValue | --------------------- * | | | ---------------- | Classification | ----------------
I have the following code in my IndicatorEdit.xhtml:
<s:decorate template="layout/edit.xhtml"> <ui:define name="label">Classification values</ui:define> <rich:dataList id="classificationList" var="classification" value="#{classificationList.resultList}" rendered="#{not empty classificationList.resultList}"> #{classification.classificationName} <h:selectManyCheckbox id="classificationValues" value="#{indicatorHome.instance.classificationValues}"> <s:selectItems value="#{classification.classificationValues}" var="classificationValue" label="#{classificationValue.valueText}" /> <s:convertEntity /> </h:selectManyCheckbox> </rich:dataList> </s:decorate>
What I'm trying to do is to group classification values according to their classification so the user could choose the classification values for each indicator
in an organized way. The IndicatorEdit form should look like this:
------------------------------------------------------------------ Indicator Name Sales Description Amount of monthly sales in thousand of dollars Classifications BSC perspective _ Financial _ Customer _ Process Classification 2 _ Class2 value1 _ Class2 value2 _ Class2 value3 Comments This is a test indicator ------------------------------------------------------------------
The problem arises when I press the Save button, since Seam only saves the checked values corresponding to the last classification shown (in this case, of Classification 2
).
The actual sequence is that all records are first deleted and then, the selected records of the last classification are saved again. The console log I have when I select two values of the second list (regardless of how many I selected in the previous ones) is:
16:04:11,526 INFO [STDOUT] Hibernate: delete from bizwatch.indicator_classification where indicator_id=? 16:04:11,530 INFO [STDOUT] Hibernate: insert into bizwatch.indicator_classification (indicator_id, classification_value_id) values (?, ?) 16:04:11,532 INFO [STDOUT] Hibernate: insert into bizwatch.indicator_classification (indicator_id, classification_value_id) values (?, ?)
Has anyone worked with similar use cases?
Please let me know.