I'm having issue doing a one-to-one mapping association where i get the 'broken column mapping for' error.
Exception in
thread "main" org.hibernate.MappingException: broken column mapping for: department.id of: org.tutorial.hibernate.xml.dto.UserXML
Would appreciate any help.
Thanks.
Here are my code:
a. Class UserXML
public class UserXML {
private SocialInsuranceXML sin;
private Date dateJoined;
private
String remarks;
private AddressXML homeAddress;
private AddressXML mailingAddress;
private Collection<AddressXML> addressHistory = new ArrayList<AddressXML>();
private DepartmentXML department;
public SocialInsuranceXML getSin() {
return sin;
}
public void setSin(SocialInsuranceXML sin) {
this.sin = sin;
}
public Date getDateJoined() {
return dateJoined;
}
public void setDateJoined(Date dateJoined) {
this.dateJoined = dateJoined;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public AddressXML getHomeAddress() {
return homeAddress;
}
public void setHomeAddress(AddressXML homeAddress) {
this.homeAddress = homeAddress;
}
public AddressXML getMailingAddress() {
return mailingAddress;
}
public void setMailingAddress(AddressXML mailingAddress) {
this.mailingAddress = mailingAddress;
}
public Collection<AddressXML> getAddressHistory() {
return addressHistory;
}
public void setAddressHistory(Collection<AddressXML> addressHistory) {
this.addressHistory = addressHistory;
}
public DepartmentXML getDepartment() {
return department;
}
public void setDepartment(DepartmentXML department) {
this.department = department;
}
@Override
public String toString() {
return "UserXML [sin=" + sin + ", dateJoined=" + dateJoined + ", remarks=" + remarks + ", homeAddress=" + homeAddress
+ ", mailingAddress=" + mailingAddress + ", addressHistory=" + addressHistory + ", department=" + department + "]";
}
}
b. Class DepartmentXML
public class DepartmentXML {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "department [id=" + id + ", name=" + name + "]";
}
}
c. userxml.hbm.xml
<hibernate-mapping package="org.tutorial.hibernate.xml.dto">
<class name="UserXML" table="user_xml">
<composite-id name="sin" class="org.tutorial.hibernate.xml.dto.SocialInsuranceXML">
<key-property name="id" column="sin_id" />
<key-property name="name" column="user_name" />
</composite-id>
<property name="dateJoined" column="date_joined" type="date" />
<property name="remarks" column="remarks" type="text" />
<component name="homeAddress">
<property name="street" column="home_street_name" />
<property name="city" column="home_city_name" />
<property name="state" column="home_state_name" />
<property name="zipCode" column="home_zipcode_name" />
</component>
<component name="mailingAddress">
<property name="street" column="mailing_street_name" />
<property name="city" column="mailing_city_name" />
<property name="state" column="mailing_state_name" />
<property name="zipCode" column="mailing_zipcode_name" />
</component>
<idbag name="addressHistory" table="address_history_xml">
<collection-id type="long" column="address_id">
<generator class="hilo" />
</collection-id>
<key>
<column name="sin_id" />
<column name="user_name" />
</key>
<composite-element class="org.tutorial.hibernate.xml.dto.AddressXML">
<property name="street" column="street_name" />
<property name="city" column="city_name" />
<property name="state" column="state_name" />
<property name="zipCode" column="zipcode_name" />
</composite-element>
</idbag>
<one-to-one name="department" class="org.tutorial.hibernate.xml.dto.DepartmentXML" />
</class>
</hibernate-mapping>
d. departmentxml.hbm.xml
<hibernate-mapping package="org.tutorial.hibernate.xml.dto">
<class name="DepartmentXML" table="department_xml">
<id name="id" column="department_id" />
<property name="name" column="department_name" />
</class>
</hibernate-mapping>