-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to write Composite Primary Keys mapping??
PostPosted: Fri Aug 22, 2008 3:44 am 
Newbie

Joined: Fri Aug 22, 2008 3:12 am
Posts: 4
HI Friends,

Can you plase help me out to use Composite mapping

here is my table structure

DVC_ID NUMBER(6,0)
CMD_CODE VARCHAR2(10 BYTE)
COMMAND_SCRIPT VARCHAR2(2000 BYTE),
REQUIRES_PARAMS
CONSTRAINT "PK_PROV_COMMANDS" PRIMARY KEY("DVC_ID", "CMD_CODE")
CONSTRAINT "PROV_Relationship22" FOREIGN KEY ("DVC_ID")
REFERENCES "SUBSCRIBER_ADMIN"."PROV_PHYSICAL_DEVICES" ("DVC_ID") ENABLE)


Top
 Profile  
 
 Post subject: are you using annotations?
PostPosted: Fri Aug 22, 2008 7:37 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
or xml?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 7:41 am 
Newbie

Joined: Fri Aug 22, 2008 3:12 am
Posts: 4
Yes


Top
 Profile  
 
 Post subject: there are 3 ways to do this
PostPosted: Fri Aug 22, 2008 7:48 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
i will give you one:
create a class for the PK , mark this class with @embdeded.
in this class you have 2 fields annotated with @id

in the class that need a composiste pk you have a PK field annotated with @embededid


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 7:52 am 
Newbie

Joined: Fri Aug 22, 2008 3:12 am
Posts: 4
If you dont mind can u elaborate breif

class design and hbm file


Top
 Profile  
 
 Post subject: i thought that you are use in annotation
PostPosted: Fri Aug 22, 2008 7:54 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
the solution i gave you is for annotation


Top
 Profile  
 
 Post subject: An example
PostPosted: Fri Aug 22, 2008 12:14 pm 
Newbie

Joined: Fri Aug 22, 2008 11:07 am
Posts: 6
Location: Italy
Code:
<class name="TestCompositeImpl"
      table="test_composite" proxy="TestCompositeImpl">
<meta attribute="implement-equals">true</meta>
<composite-id class="TestCompositePK" >
         <key-property name="id" column="DVC_ID"  type="long" />
         <key-property name="code" column="CMD_CODE" type="java.lang.String" length="10" />   
      </composite-id>

.....



TestCompositeImpl is the class that map the entire table, TestCompositePK is the class that map the key and is usefull for load object by key.

Code:
public class TestCompositePK implements Serializable{
Long id;
String code;
...

public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result
                + ((code== null) ? 0 : code.hashCode());
        return result;
    }

public boolean equals(Object obj) {
...
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

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.