Hibernate version: 3.0.3
Mapping documents:
Code:
<class name="Company">
<id name="id" column="id" type="java.lang.Long">
<generator class="native"/>
</id>
<component name="contact" class="Contact">
<set name="addresses" lazy="false" inverse="true" cascade="all-delete-orphan" sort="unsorted">
<key column="companyid"/>
<one-to-many class="Address"/>
</set>
[...]
</class>
<class name="User">
<id name="id" column="id" type="java.lang.Long">
<generator class="native"/>
</id>
<component name="contact" class="Contact">
<set name="addresses" lazy="false" inverse="true" cascade="all-delete-orphan" sort="unsorted">
<key column="userid"/>
<one-to-many class="Address"/>
</set>
[...]
</class>
Code between sessionFactory.openSession() and session.close():Code:
Company c = new Company();
c.setCompanyType("Golf");
Contact con = new Contact();
con.setOrganisation("Test Company");
con.setCompany(true);
companyManager.saveCompany(c);
Address a = new Address();
a.setPostcode("SL6 0HE");
a.setLabel("Home");
con.setAddresses(new HashSet());
con.getAddresses().add(a);
c.setContact(con);
companyManager.saveCompany(c);
Full stack trace of any exception that occurs:Name and version of the database you are using:MySQL 4.1.10
The generated SQL (show_sql=true):Code:
Hibernate: insert into Company (companyType, department, dob, firstName, company, jobTitle, lastName, middleName, organisation, suffix, title, modificationDate, creationDate) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Address (address1, address2, address3, city, country, county, label, postcode) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update Company set companyType=?, department=?, dob=?, firstName=?, company=?, jobTitle=?, lastName=?, middleName=?, organisation=?, suffix=?, title=?, modificationDate=?, creationDate=? where id=?
Debug level Hibernate log excerpt:Code:
DEBUG - CompanyDAOHibernate.saveCompany(36) | companyId set to: 4
DEBUG - CompanyDAOHibernate.saveCompany(36) | companyId set to: 4
.. a bit more info.
So this is what I have at the moment but when I save the company the address is stored but the companyid fk in Address is null, what do I need to add to the mapping the associate the Company with the Address?
Many thanks,
Adam