Good After Noon Sir ,
Now, I m using Hibernate Technology for my project.
I m confuse in case of more than one primary field means composite key case. I know in hibernate mapping file we can use <composite-id> tag for this case. But in this tag an attribute is use named "name" . The value of this name attribute is any field java file or other.
In composite case i have made an extra java means an applicaion identity class which implements an interface java.io.Serializable and also override the methods equals and hashcode .
I know i must made an extra class for composite case. But what value i can give in name attribute of composite-tag .
I m give u an example of composite case mapping file.
----------------------------------------------------------------------
<hibernate-mapping>
<class name = "C" table = "CTable">
<id name = "id" type = "Long" column = "id">
<generator class = "increment"/>
</id>
<property name = "aId" type = "Long" column = "aIdCol"/>
<composite-id name = "......" class = "CExtraClass">
<key-property name = "id" type = "Long"/>
<key-property name = "aId" type = "Long"/>
</composite-id>
</class>
</hibernate-mapping>
------------------------------------------------------------------------
My Java Class :
class C{
private Long id;
private Long aId;
private void setId(Long newId){
this.id = newId;
}
public Long getId(){
return id;
}
private void setAId(Long newAId){
this.aId = newAId;
}
public Long getAId(){
return aId;
}
}
class CExtraClass implements java.io.Serializable{
Long id;
Long aId;
private Long getId(){
return this.id;
}
private void setId(long newId){
if(this.id == newId) {
return ;
}
if((this.id == newId)
|| ((this.id == null) && (newid == null))
|| ((this.id != null) && (newid != null) && (this.id.equals(newId)))) {
return ;
}
this.id = newId;
}
private Long getAId(){
return this.aId;
}
private void setAId(long newAId){
if(this.aId == newAId) {
return ;
}
if((this.aId == newAId)
|| ((this.aId == null) && (newAId == null))
|| ((this.aId != null) && (newAId != null) && (this.aId.equals(newAId)))) {
return ;
}
this.aId = newAId;
}
public boolean equals(){
----------
----------
----------
return true;
}
public int hashcode(){
return 100;
}
}
Table :
The table CTable which is use in this example is explain below :
create table CTable(
id bigint ,
aIdCol bigint ,
primary key (id,aIdCol)
);
So can u give me an example of java file of composite key case .
Mainly i want what value or what change i can do in java file in case of composite case. What value i can give in name attribute of composite-id tag.Pls suggest me for this case.
|