-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need Help -- composite-id
PostPosted: Thu Oct 30, 2003 6:11 am 
Newbie

Joined: Mon Oct 06, 2003 4:18 am
Posts: 4
i have just one table(table A), three column (a1,a2,a3)to produce primary key, how should i edit my A.hbm.xml and the Aid.java

really don't know how to do this, hope there is anybody can help me


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 7:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hibernate reference guide section :
4.1.5
6.4 (the exact example you want)

Code:
import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Aid implements Serializable{
   private Long a1;
   private Long a2;
   private Long a3;

   public Long getA1() {
      return a1;
   }

   public Long getA2() {
      return a2;
   }

   public Long getA3() {
      return a3;
   }

   public void setA1(Long long1) {
      a1 = long1;
   }

   public void setA2(Long long1) {
      a2 = long1;
   }

   public void setA3(Long long1) {
      a3 = long1;
   }
   
   public boolean equals(Object other) {
        if ( !(other instanceof Aid) ) return false;
        Aid castOther = (Aid) other;
        return new EqualsBuilder()
            .append(this.getA1(), castOther.getA1())
            .append(this.getA2(), castOther.getA2())
            .append(this.getA3(), castOther.getA3())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getA1())
            .append(getA2())
            .append(getA3())
            .toHashCode();
    }

}

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.