How to represent oracle composite key in hibernate

Hello,
  I will create an oracle table with composite key.. How do i represent  the composite key in the hibernate file and in the bean

CREATE TABLE FAVORITES
(
  FAVORITE_ID VARCHAR2(20) NOT NULL,
  TITLE VARCHAR2(200),
  CITY VARCHAR2(40),
  STATE_CODE VARCHAR2(40),
  STATE_NAME VARCHAR2(20),
  STRING VARCHAR2(100),
  USERID VARCHAR2(30) NOT NULL
, CONSTRAINT FAVORITE_PK PRIMARY KEY
  (
    FAVORITE_ID,
    USERID
  )
  ENABLE
)
;

Open in new window


This is my bean
package com.rusapi.ca.beans;

public class Favorites {
	
	String jobId,userId;
	String city,stateCode,stateName,string;
	String type,postingDate;
	
	public String getjobId(){
		return this.jobId;
	}
	public void setId(String jobId){
		this.jobId = jobId;
	}
	public String getUserId(){
		return this.userId;
	}
	public void setUserId(String userId){
		this.userId = userId;
	}
	public String getCity(){
		return this.city;	
	}
	public void setCity(String city){
		this.city = city;
	}
	public String getStateCode(){
		return this.stateCode;
	}
	public void setStateCode(String stateCode){
		this.stateCode = stateCode;
	}
	public String getStateName(){
		return this.stateCode;
	}
	public void setStateName(String stateName){
		this.stateName = stateName;
	}
	public String getString(){
		return this.string;
	}
	public void setString(String string){
		this.string = string;
	}
	public String getType(){
		return this.type;
	}
	public void setType(String type){
		this.type = type;
	}
	public String getPostingDate(){
		return this.postingDate;
	}
	public void setPostingDate(String postingDate){
		this.postingDate = postingDate;
	}
}

Open in new window


hibernate file stub
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.rusapi.ca.beans">

    <class name="Favorites" table="Favorites">	
     	<id name="" column="" />	
    </class>

</hibernate-mapping>

Open in new window


Thanks for your help
chand pbAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex [***Alex140181***]Software DeveloperCommented:
I think the key annotations here are "EmbeddedId" and "IdClass" as shown here http://www.objectdb.com/java/jpa/entity/id#Composite_Primary_Key_

and some other nice samples here http://stackoverflow.com/questions/3585034/how-to-map-a-composite-key-with-hibernate

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.