I think my problem is really that the foreign key is part of the composite id. Has anyone done something like this?
________________________________ From: Travers Snyman [mailto:[EMAIL PROTECTED] Sent: 09 February 2007 01:54 PM To: [email protected] Subject: [appfuse-user] Weird problem with one-to-many and composite id Hi, I have a one-to-many relationship model with the child side not having a primary key. So I use a composite key. The foreign key on the child side is part of the composite key. When I persist the model, the parent side is written to the table, but instead of an insert of the child side, if I look at the sql log it attemtps to do an update. I have looked at the hibernate docs and some examples and from what I understand, I am doing things right. Please assist if I am missing something. I use Appfuse 1.9.4 with hibernate. See my classes below: Thanks Travers //// parent class * @struts.form include-all="true" extends="BaseForm" * @hibernate.class table="qc_query_control" */ public class QueryControl extends BaseObject implements Serializable { private static final long serialVersionUID = 3832626166523359411L; protected Long id; < and rest of attributes> protected Set queryParameters = new HashSet(); // one to many relationship < then the getter for queryParameters> * @hibernate.set table = qp_query_parameter cascade="all-delete-orphan" role="oneToMany" lazy="false" * @hibernate.collection-key column="qp_qc_uid" * @hibernate.collection-one-to-many class="cam.model.QueryParameter" */ public Set getQueryParameters() { return queryParameters; } // Then the child class * @struts.form include-all="false" extends="BaseForm" * @hibernate.class table="qp_query_parameter" */ public class QueryParameter extends BaseObject implements Serializable { private static final long serialVersionUID = 3690147920654049848L; protected QueryParameterPK id; protected String qpMatchType; protected Long qpUserId; protected QueryControl queryControl; /** * Returns a reference to the queryControl it belongs to * @hibernate.many-to-one column="qp_qc_uid" insert="false" update="false" * class="cam.model.QueryControl" * cascade="none" */ public QueryControl getQueryControl() { return queryControl; } // the class QueryParameterPK is the composite class public class QueryParameterPK extends BaseObject implements Serializable { private static final long serialVersionUID = 3690147920654049848L; protected Long qpQcUid; protected Long qpQptUid; < the attribute qpQcUid refers to the foreign key> * @hibernate.property column="qp_qc_uid" not-null="true" */ public Long getQpQcUid() { return qpQcUid; } * @hibernate.property column="qp_qpt_uid" not-null="true" */ public Long getQpQptUid() { return qpQptUid; } * @hibernate.property column="qp_start_date" not-null="true" */ public Date getQpStartDate() { return qpStartDate; } public void setQpStartDate(Date qpStartDate) { this.qpStartDate = qpStartDate; }
