Many-to-many example using Hibernate
Pertinent code for the two objects in the many-to-many relationship follows. Hibernate generates a third table, form_field_bridge, to bind together the relationship between multiple forms and fields.
FormField:
/**
* @return
* @hibernate.set inverse="false"
* lazy="false"
* cascade="save-update"
* table="form_field_bridge"
* @hibernate.collection-key column="field_id"
* @hibernate.collection-many-to-many class="org.zeprs.data.Form" column="form_id"
*/
public Set getForms()
{
return forms;
}
public void setForms(Set form)
{
this.forms = form;
}
Form:
/**
* @return
* @hibernate.set inverse="true"
* lazy="false"
* cascade="save-update"
* table="form_field_bridge"
* sort="org.zeprs.display.util.DisplayOrderComparator"
* @hibernate.collection-key column="form_id"
* @hibernate.collection-many-to-many class="org.zeprs.data.FormField" column="field_id"
*/
public Set getFields() {
return fields;
}
public void setFields(Set field) {
this.fields = field;
}
September 4th, 2004 at 7:59 pm
any reasons why a Form.getFields(), will not return collection of Fields? after a session.save ?? i am using spring/hibernate , thanks!
September 5th, 2004 at 4:42 pm
Do i use a formfieldbridge object also??..i generated the assocation table as well, but it has porblems using java2hbm
September 5th, 2004 at 5:44 pm
Jeryl: try a session.refresh(Form) before retreiving the collection.