Hi all,
I am trying to develop a hibernate application using one-to-one association. I have two POJOs named Employee and Message, I have a table employee. The employee table have the empname, empid, salary, company, email, message as the columns. My question is If I set the value in the Message POJO, that value has to be inserted into the database. I got the output what I expected with the many-to-one tag. But now I want to get the output with one-to-one association. Can anybody pls help me how to do that ??
**** I want to insert the data into a single table using two POJOs ****
Here is my code :
Employee POJO :
package events;
public class Employee {
private
String empname;
private int empid;
private int salary;
private String company;
private String email;
private Message message;
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
public Employee() {
}
}
Message POJO :
package events;
public class Message extends Employee{
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String message) {
this.msg = message;
}
public Message() {
}
}
Employee.hbm.xml :
<?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>
<class name="events.Employee" table="employee">
<id name="empname" column="empname"></id>
<property name="empid" column="empid"></property>
<property name="salary" column="salary"></property>
<property name="company" column="company"></property>
<property name="email" column="email"></property>
<many-to-one name="message" class="events.Message" column="message" cascade="all"/>
</class>
</hibernate-mapping>
Can anybody pls tell me how to get the output by using <one-to-one/> ???