-->
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: xdoclet composite primary key mapping for foreign key in hib
PostPosted: Wed Feb 16, 2011 10:51 am 
Newbie

Joined: Sat Jan 17, 2009 8:50 am
Posts: 3
Hello All,
I've on Table which have a composite Key as a Primary key other table needs its reference as a Composite Key.

Table1: SPECIALITY{
categoryid,
specialityid,
discription
}
PK( categoryid,specialityid)

Table2: SpcialityVSDiscription{
id PK,
categid,
specialityid,
discription
}


IN DB SpcialityVSDiscription table colums(categid,specialityid) mapped with SPECIALTY TABLES PK as FK.

Now I've my classes Like this:

Code:
/**
* @author
* @hibernate.class table="SPECIALTY"
*
*/
public class Specialtymaster implements java.io.Serializable {

   // Fields

   private SpecialtymasterId id;
/**
    * @return id
    * @hibernate.composite-id
    */   
   public SpecialtymasterId getId() {
      return this.id;
   }
   /**
    *
    * @param id
    */
   public void setId(SpecialtymasterId id) {
      this.id = id;
   }
   /**
    * @return description
    * @hibernate.property  type="java.lang.String" column="DESCRIPTION"  length="50"
    *
    */
   public String getDescription() {
      return this.description;
   }
   /**
    *
    * @param description
    */
   public void setDescription(String description) {
      this.description = description;
   }
}


Code:
public class SpecialtymasterId implements java.io.Serializable {

   // Fields

   private Majorcategorymaster majorcategorymaster;
   private Integer specialtyid;

   // Constructors

   /** default constructor */
   public SpecialtymasterId() {
   }

   /** full constructor */
   public SpecialtymasterId(Majorcategorymaster majorcategorymaster,
         Integer specialtyid) {
      this.majorcategorymaster = majorcategorymaster;
      this.specialtyid = specialtyid;
   }

   // Property accessors
   /**
    * @return majorcategorymaster
    * @hibernate.key-many-to-one  class="com.spedulerapp.components.common.metadata.model.hbm.Majorcategorymaster" column="CATEGORYID"
    */

   public Majorcategorymaster getMajorcategorymaster() {
      return this.majorcategorymaster;
   }
   /**
    *
    * @param majorcategorymaster
    */
   public void setMajorcategorymaster(Majorcategorymaster majorcategorymaster) {
      this.majorcategorymaster = majorcategorymaster;
   }
   /**
    * @return specialtyid
    * @hibernate.key-property  type="java.lang.Integer" column="SPECIALTYID"
    *
    */
   public Integer getSpecialtyid() {
      return this.specialtyid;
   }
   /**
    *
    * @param specialtyid
    */
   public void setSpecialtyid(Integer specialtyid) {
      this.specialtyid = specialtyid;
   }


Code:
/**
*
* @author Raghvendra
* @hibernate.class table="speciality_business_desc_combination"
*
*/
public class Specialitybusinessdescription implements Serializable{
   private Integer id;
   private Specialtymaster specialty;
   private Businessdiscriptionsample  businessdiscriptionsample;
   private Timestamp dateupdated;
   private String userupdated;
   
   public Specialitybusinessdescription(){
      super();
   }

   /**
    * @return the id
    * @hibernate.id generator-class="increment" column="ID" type="java.lang.Integer"
    */
   public Integer getId() {
      return id;
   }

   /**
    * @param id the id to set
    */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
    * @return the specialty
    * @hibernate.many-to-one  column="IDCATEGORY" column="IDSPECIALITY" not-null="true" foreign-key ="true" class="com.spedulerapp.components.common.metadata.model.hbm.Specialtymaster" fetch="select"
    *
    */
   public Specialtymaster getSpecialty() {
      return specialty;
   }

   /**
    * @param specialty the specialty to set
    */
   public void setSpecialty(Specialtymaster specialty) {
      this.specialty = specialty;
   }

   /**
    * @return the businessdiscriptionsample
    * @hibernate.many-to-one  class="com.spedulerapp.components.common.metadata.model.hbm.Businessdiscriptionsample" fetch="select"
    * @hibernate.
    */
   public Businessdiscriptionsample getBusinessdiscriptionsample() {
      return businessdiscriptionsample;
   }

   /**
    * @param businessdiscriptionsample the businessdiscriptionsample to set
    */
   public void setBusinessdiscriptionsample(
         Businessdiscriptionsample businessdiscriptionsample) {
      this.businessdiscriptionsample = businessdiscriptionsample;
   }


column="IDCATEGORY" column="IDSPECIALITY"
SO how to map this Composite-Key PK vs FK reference.

Please help me. as I've tried with many-to-one, join etc but its not working
thank you
regards
Kirti

_________________
kirti


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.