i am newbie to hibernate, Here are the two objects
1)
Code:
public class Employee implements Serializable {
private Long userId;
private Long supportId;
private Long typeId;
private String firstName;
private String lastName;
private String emailAddress;
private String phoneNumber;
private String userFlag;
private String companyId;
private SupportBean supportBean;
public Employee() {
super();
setUserFlag("Y");
setTypeId(new Long(6));
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Long getSupportId() {
return supportId;
}
public void setSupportId(Long supportId) {
this.supportId = supportId;
}
public Long getTypeId() {
return typeId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
public Long getCompanyIdId() {
return companyId;
}
public void setCompanyId(Long companyId) {
this.companyId = companyId;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public SupportBean getSupportBean() {
return supportBean;
}
public void setSupportBean(SupportBean supportBean) {
this.supportBean = supportBean;
}
}
2)
Code:
public class SupportBean implements Serializable {
private Long supportId;
private String name;
private String status;
private Employee employee;
public SupportBean() {
super();
}
public Long getSupportId() {
return supportId;
}
public void setSupportId(Long supportId) {
this.supportId = supportId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
3) Employee.hbm.xml
Code:
<hibernate-mapping package="com.emc.servicecenter.user">
<class name="Employee" table="table_employee">
[b] <id name="userId" column="user_id"/>[/b]
[color=#BF0040]<property name="supportId" column="support_id"></property>[/color]
<property name="typeId" column="type_id"></property>
<property name="firstName" column="first_name"></property>
<property name="lastName" column="last_name"></property>
<property name="emailAddress" column="email_address"></property>
<property name="phoneAddress" column="phone_address"></property>
<property name="userFlag" column="user_flag"></property>
[color=#4000FF] <property name="companyId" column="company_id"></property> [/color]
[b] <one-to-one name="supportBean" class="SupportBean" constrained="true"/>[/b]
</class>
</hibernate-mapping>
4)
Code:
<hibernate-mapping package="com.emc.servicecenter.user">
<class name="SupportBean" table="table_support">
[b] <id name="supportId" column="support_id"></id>[/b]
<property name="name" column="name"></property>
<property name="status" column="status"></property>
[b] <one-to-one name="employee" class="Employee"/>[/b]
</class>
</hibernate-mapping>
Here is how both are related
1) Employee has one-to-one with SupportBean object
2) userId is the primary key of Employee object
3) supportId is the Foreign Key of Employee Object
3) supportId is the PK of SupportBean object
so i have a small test like below
SessionFactory sessionFactory = new Configuration().configure("xxx.cfg.xml").buildSessionFactory();
session = sessionFactory.openSession();
Employee emp = (Employee)session.get(Employee.class,new Long(1000));
System.out.println("output=" + emp.getFirstName() + ":" + emp.getSupportBean());
results: Jack : null
am i doing anything wrong with the mapping, could some one shed light on this please
thanks
DP