<hibernate-mapping>
<class name="safeIp" table="safeIP">
<composite-id name="safeIpId" class="safeIp">
            <key-property name="IpGroup" type="integer">
                <column name="IPgroup" />
            </key-property>
            <key-property name="Ip" type="integer">
                <column name="IP" />
            </key-property>
</composite-id>
.......................
.......................
 </class>
</hibernate-mapping>
这样就行,不过如果能改数据库的话,我还是建议LZ加一个Id字段最好。复合主键不好使的说。

解决方案 »

  1.   

    看看我给你的代码,只要拷贝过去就可以用了
    package model;/**
     * AbstractSafeip
     */public abstract class AbstractSafeip  implements java.io.Serializable {
        // Fields         private SafeipId id;
        // Constructors    /** default constructor */
        public AbstractSafeip() {
        }    
        /** full constructor */
        public AbstractSafeip(SafeipId id) {
            this.id = id;
        }   
        // Property accessors    public SafeipId getId() {
            return this.id;
        }
        
        public void setId(SafeipId id) {
            this.id = id;
        }
    }package model;
    // Generated by MyEclipse - Hibernate Tools/**
     * Safeip
     */
    public class Safeip extends AbstractSafeip implements java.io.Serializable {    // Constructors    /** default constructor */
        public Safeip() {
        }    
        /** full constructor */
        public Safeip(SafeipId id) {
            super(id);        
        }
       
    }package model;/**
     * SafeipId 
     */public class SafeipId  implements java.io.Serializable {
        // Fields         private long ipgroup;
         private long ip;
        // Constructors    /** default constructor */
        public SafeipId() {
        }       
        // Property accessors    public long getIpgroup() {
            return this.ipgroup;
        }
        
        public void setIpgroup(long ipgroup) {
            this.ipgroup = ipgroup;
        }    public long getIp() {
            return this.ip;
        }
        
        public void setIp(long ip) {
            this.ip = ip;
        }
          public boolean equals(Object other) {
             if ( (this == other ) ) return true;
     if ( (other == null ) ) return false;
     if ( !(other instanceof SafeipId) ) return false;
     SafeipId castOther = ( SafeipId ) other; 
             
     return (this.getIpgroup()==castOther.getIpgroup())
     && (this.getIp()==castOther.getIp());
       }
       
       public int hashCode() {
             int result = 17;
             
             result = 37 * result + (int) this.getIpgroup();
             result = 37 * result + (int) this.getIp();
             return result;
       }   
    }file name : Safeip.hbm.xml<?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="model.Safeip" table="SAFEIP" schema="YPMS">
            <composite-id name="id" class="model.SafeipId">
                <key-property name="ipgroup" type="long">
                    <column name="IPGROUP" precision="10" scale="0" />
                </key-property>
                <key-property name="ip" type="long">
                    <column name="IP" precision="10" scale="0" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>