This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to use one-to-one association

Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) { = company;
public String getEmail() {
return email;
public void setEmail(String 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"

<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"/>

Can anybody pls tell me how to get the output by using <one-to-one/> ???
Ranch Hand
Posts: 57
What's a year in metric? Do you know this metric stuff tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic