Hi fangEve,
it looks like it's a typical parent-child (one-to-many) relationship. To insert into both tables do the following:
1 / - Java code: add an instance of your Thread POJO class into
Attachment POJO class (with setter /getter )
2/ - Java code: add a Collection of Attachments into your Thread POJO (e.g. a Set)
3/ - add a convenience method to add an Attachment into a Thread (into your Thread POJO). E.g :
Code:
public void addAttachment(Attachment at{
at.setThread(this);
if (attachments == null) {
attachments = new HashSet();
}
attachments.add(at);
}
4/ - Mapping: into your Thread.hbm.xml add the one-to-many relationship. E.g
Code:
<set name="attachments" cascade="save-update">
<key column="THREAD_ID" not-null="true"/>
<one-to-many class="bla.bla.Attachment" />
</set>
5/ - Mapping: into your Atachment.hbm.xml add the many-to-one relationship. E.g:
Code:
<many-to-one name="customer" foreign-key="CUSTOMER_ID" not-null="true"/>
6/ - Don't forget to use id generator class="native" for your 'auto_increment' stuff.
That should work fine.
Don't forget to rate
Chucky
----------------
thread
id (PK) auto-increment
msgText
submitDate
username
attachment
id(PK)
threadId (FK to thread 'id' column)
file
filename