I tried your code, cut away some parts and it seem to work here. Below you can find my code. I used Hibernate 3.1 with PostgreSQL 8.1
Please consider to cut away everything from your code until you come accross the issue.
Please post this here.
Sebastian
Code:
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
Telephone telephone = new Telephone();
telephone.setIsdn("123");
telephone.setNumber("345");
Telephone t2 = new Telephone();
t2.setIsdn("1234");
t2.setNumber("3434");
Test test = new Test();
test.setPrivatePhone(t2);
test.setCompanyName("comp");
test.setWorkPhone(telephone);
session.save(test);
tx.commit();
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="de.laliluna.component1">
<class name="Test" lazy="false" table="test" optimistic-lock="none">
<id name="id" type="integer" unsaved-value="null" column="id">
<generator class="sequence">
<param name="sequence">test_id_seq</param>
</generator>
</id>
<property name="companyName" type="string" column="company_name" not-null="true" />
<component name="workPhone" update="true" insert="true" class="de.laliluna.component1.Telephone">
<property name="isdn" type="string" column="isdn" length="10" not-null="true" />
<property name="number" type="string" column="number" length="15" not-null="true" />
</component>
<component name="privatePhone" update="true" insert="true" class="de.laliluna.component1.Telephone">
<property name="isdn" type="string" column="isdn2" length="10" not-null="true" />
<property name="number" type="string" column="number2" length="15" not-null="true" />
</component>
</class>
</hibernate-mapping>
Code:
package de.laliluna.component1;
public class Telephone {
private String isdn;
private String number;
public String getIsdn() {
return isdn;
}
public void setIsdn(String isdn) {
this.isdn = isdn;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
Code:
package de.laliluna.component1;
public class Test {
private Integer id;
private String companyName;
private Telephone workPhone;
private Telephone privatePhone;
public Telephone getPrivatePhone() {
return privatePhone;
}
public void setPrivatePhone(Telephone privatePhone) {
this.privatePhone = privatePhone;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Telephone getWorkPhone() {
return workPhone;
}
public void setWorkPhone(Telephone workPhone) {
this.workPhone = workPhone;
}
}