In my application I am using struts and hibernate together to edit the contents of a database. To load data from the database I am doing something like this in the action execute method:
Code:
DbObject dbobject = (DbObject)session.load(DbObject.class, new Long(idObj));
org.apache.struts.validator.DynaValidatorActionForm myform = (org.apache.struts.validator.DynaValidatorActionForm) form;
org.apache.commons.beanutils.PropertyUtils.copyProperties(myform, dbobject);
session.close();
and to save information from the form back to the database, I am doing something like this in action execute method:
Code:
org.apache.struts.validator.DynaValidatorActionForm myform = (org.apache.struts.validator.DynaValidatorActionForm) form;
DbObject dbobject = (DbObject).load(DbObject.class, (Serializable) myform.get("idObj"));
org.apache.commons.beanutils.PropertyUtils.copyProperties(dbobject,myform);
session.save(dbobject);
session.flush();
session.connection().commit();
session.close();
(Validation of data is being done using the validation capabilities of struts)
This works nicely where the textual and numeric data where the data is all in one table. It can work fairly well when there is a simple lookup to information in another table, single properties can be set manually. However I would like to know how to make this work efficiently for many to many type data. This is the case where in the main hibernate object (in the above examples dbobject) there is a property which is a java.util.Set which is a set of the 'selected' objects from a third table. In the Struts form, I would want this kind of information to appear as a multiple select list box, or an array of check boxes. What is the best way of projecting this information onto a struts form object from the hibernate object for editing, and visa versa for storing.
Thanks in advance for your suggestions!