-->
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 in Composite Case !!
PostPosted: Wed Dec 06, 2006 6:53 am 
Newbie

Joined: Tue Apr 25, 2006 6:34 am
Posts: 2
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.


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.