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