-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with One To One Mapping
PostPosted: Thu May 05, 2011 6:02 pm 
Newbie

Joined: Thu May 05, 2011 5:53 pm
Posts: 1
Code:
Parent class with common fields:

@MappedSuperclass
@Transactional
public abstract class PersistenceBase implements Serializable{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;
    @Column(name = "CANCEL_PK")
    private Long cancelPk;
    @Column(name = "CANCEL_STATUS")
    private String cancelStatus;
    @Column(name = "MODIFIED_DATE")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date modifiedDate;
    @Column(name = "MODIFIED_BY")
    private String modifiedBy;
    @Column(name = "INSERTED_DATE")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date insertedDate;
    @Column(name = "INSERTED_BY")
    private String insertedBy;
   
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getCancelPk() {
        return cancelPk;
    }

    public void setCancelPk(Long cancelPk) {
        this.cancelPk = cancelPk;
    }

    public String getCancelStatus() {
        return cancelStatus;
    }

    public void setCancelStatus(String cancelStatus) {
        this.cancelStatus = cancelStatus;
    }

    public String getInsertedBy() {
        return insertedBy;
    }

    public void setInsertedBy(String insertedBy) {
        this.insertedBy = insertedBy;
    }

    public Date getInsertedDate() {
        return insertedDate;
    }

    public void setInsertedDate(Date insertedDate) {
        this.insertedDate = insertedDate;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }
}

Child Classes:

Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.versicle.emr.dao.bean;

import com.versicle.emr.dao.base.PersistenceBase;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

import javax.persistence.Table;
import javax.persistence.Temporal;

/**
*
* @author Souvik
*/
@Entity
@Table(name = DoctorDetails.TABLE_NAME)
public class DoctorDetails extends PersistenceBase {

    public static final String TABLE_NAME = "DOCTOR_DETAILS";
    @Column(name = "doctor_code")
    private String doctorCode;
    @Column(name = "first_name")
    private String firstName;
    @Column(name = "middle_name")
    private String lastName;
    @Column(name = "last_name")
    private String middleName;
    @Column(name = "title")
    private String title;
    @Column(name = "location")
    private String location;
    @Column(name = "ss_no")
    private String ssNo;
    @Column(name = "tax_id")
    private String taxId;
    @Column(name = "license")
    private String license;
    @Column(name = "dea_no")
    private String deaNo;
    @Column(name = "dob_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dobDate;
    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "ID")
    private ContactDetails contactDetails = null;

    public ContactDetails getContactDetails() {
        return contactDetails;
    }

    public void setContactDetails(ContactDetails contactDetails) {
        this.contactDetails = contactDetails;
    }

    public String getDeaNo() {
        return deaNo;
    }

    public void setDeaNo(String deaNo) {
        this.deaNo = deaNo;
    }

    public Date getDobDate() {
        return dobDate;
    }

    public void setDobDate(Date dobDate) {
        this.dobDate = dobDate;
    }

    public String getDoctorCode() {
        return doctorCode;
    }

    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }

    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 String getLicense() {
        return license;
    }

    public void setLicense(String license) {
        this.license = license;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    public String getSsNo() {
        return ssNo;
    }

    public void setSsNo(String ssNo) {
        this.ssNo = ssNo;
    }

    public String getTaxId() {
        return taxId;
    }

    public void setTaxId(String taxId) {
        this.taxId = taxId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}


Code:
@Entity
@Table(name = ContactDetails.TABLE_NAME)
public class ContactDetails extends PersistenceBase {

    public static final String TABLE_NAME = "CONTACT_DETAILS";
    @Column(name = "CONTACT_TYPE")
    private String contactType;
    @Column(name = "ADDRESS")
    private String address;
    @Column(name = "ADDRESS1")
    private String address1;
    @Column(name = "CITY")
    private String city;
    @Column(name = "STATE")
    private String state;
    @Column(name = "ZIP")
    private String zip;
    @Column(name = "WORK_PHONE")
    private String workPhone;
    @Column(name = "HOME_PHONE")
    private String homePhone;
    @Column(name = "MOBILE")
    private String mobile;
    @Column(name = "ADDRESS_ID")
    private Long addressId;
    @OneToOne(fetch = FetchType.LAZY, optional = true)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @PrimaryKeyJoinColumn
    private DoctorDetails doctorDetails;

    public DoctorDetails getDoctorDetails() {
        return doctorDetails;
    }

    public void setDoctorDetails(DoctorDetails doctorDetails) {
        this.doctorDetails = doctorDetails;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public Long getAddressId() {
        return addressId;
    }

    public void setAddressId(Long addressId) {
        this.addressId = addressId;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getContactType() {
        return contactType;
    }

    public void setContactType(String contactType) {
        this.contactType = contactType;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getWorkPhone() {
        return workPhone;
    }

    public void setWorkPhone(String workPhone) {
        this.workPhone = workPhone;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }
}



DB Script:
/*
SQLyog Community v8.82
MySQL - 5.1.46-community : Database - EMR
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`EMR` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `EMR`;

/*Table structure for table `contact_details` */

DROP TABLE IF EXISTS `contact_details`;

CREATE TABLE `contact_details` (
`ID` bigint(25) NOT NULL AUTO_INCREMENT,
`CONTACT_TYPE` varchar(1) DEFAULT NULL,
`ADDRESS` varchar(128) DEFAULT NULL,
`ADDRESS1` varchar(128) DEFAULT NULL,
`CITY` varchar(50) DEFAULT NULL,
`STATE` varchar(30) DEFAULT NULL,
`ZIP` varchar(10) DEFAULT NULL,
`WORK_PHONE` varchar(14) DEFAULT NULL,
`HOME_PHONE` varchar(14) DEFAULT NULL,
`MOBILE` varchar(14) DEFAULT NULL,
`ADDRESS_ID` bigint(25) DEFAULT NULL,
`CANCEL_PK` bigint(25) DEFAULT NULL,
`CANCEL_STATUS` varchar(1) DEFAULT NULL,
`MODIFIED_DATE` date DEFAULT NULL,
`MODIFIED_BY` varchar(50) DEFAULT NULL,
`INSERTED_BY` varchar(50) DEFAULT NULL,
`INSERTED_DATE` date DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Address_Ref_Index` (`CONTACT_TYPE`,`ADDRESS_ID`),
KEY `FK_contact_details` (`CANCEL_PK`),
KEY `FK_doctor_relation_details` (`ADDRESS_ID`),
CONSTRAINT `FK_contact_details` FOREIGN KEY (`CANCEL_PK`) REFERENCES `contact_details` (`ID`),
CONSTRAINT `FK_doctor_relation_details` FOREIGN KEY (`ADDRESS_ID`) REFERENCES `doctor_details` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Table structure for table `doctor_details` */

DROP TABLE IF EXISTS `doctor_details`;

CREATE TABLE `doctor_details` (
`ID` bigint(25) NOT NULL AUTO_INCREMENT,
`DOCTOR_CODE` varchar(20) DEFAULT NULL,
`FIRST_NAME` varchar(128) DEFAULT NULL,
`MIDDLE_NAME` varchar(128) DEFAULT NULL,
`LAST_NAME` varchar(128) DEFAULT NULL,
`TITLE` varchar(30) DEFAULT NULL,
`LOCATION` varchar(50) DEFAULT NULL,
`SS_NO` varchar(30) DEFAULT NULL,
`TAX_ID` varchar(30) DEFAULT NULL,
`LICENSE` varchar(50) DEFAULT NULL,
`DEA_NO` varchar(50) DEFAULT NULL,
`DOB_DATE` date DEFAULT NULL,
`CANCEL_STATUS` varchar(1) DEFAULT NULL,
`CANCEL_PK` bigint(25) DEFAULT NULL,
`INSERTED_BY` varchar(50) DEFAULT NULL,
`INSERTED_DATE` date DEFAULT NULL,
`MODIFIED_BY` varchar(50) DEFAULT NULL,
`MODIFIED_DATE` date DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_doctor_details` (`CANCEL_PK`),
CONSTRAINT `FK_doctor_details` FOREIGN KEY (`CANCEL_PK`) REFERENCES `doctor_details` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;



Now I have one to one relatioShip with DOCTOR_DETAILS.ID and CONTACT_DETAILS.ADDRESS_ID

When I Save with the Doctor Details the data saved in DB but the ID of the Doctor_Details doesn't stored in the CONTACT_DETAILS.ADDRESS_ID
field.

Please help me to solve the issue


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.