熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

JPA和hibernate對刪除操作的不同[4]

2022-06-13   來源: Java開源技術 

   public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        thisid = id;
    }

    @Override
    public int hashCode() {
        int hash = ;
        hash += (id != null ? idhashCode() : );
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning this method wont work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((thisid == null && otherid != null) || (thisid != null && !thisidequals(otherid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return comhadesleejpaentityPerson[id= + id + ];
    }
}

  由於JPA是不需要配置的代碼裡面已經包括了注釋所以下面附上Hibernate的映射文件為了使數據庫裡面更清楚一些所以兩者使用的表不是同一張表JPA的表是帶JPA前綴的用@Table這個注釋聲明了這一點

<?xml version= encoding=UTF?>

<!DOCTYPE hibernatemapping PUBLIC
  //Hibernate/Hibernate Mapping DTD //EN
  http://hibernatesourceforgenet/hibernatemappingdtd>
<hibernatemapping package=comhadesleejpaentity>
    <class name=Department table=Department>
        <id name=id column=departId type=long>
            <generator class=native/>
        </id>
        <property name=deptName/>
        <property name=description/>
        <set name=persons>
            <key column=deptId/>
            <onetomany class=Person/>
        </set>
    </class>
    <class name=Person table=Person>
        <id name=id column=personId type=long>
            <generator class=native/>
        </id>
        <property name=name/>
        <property name=age/>
        <manytoone name=department column=deptId class=Department/>
     </class>
</hibernatemapping>

[]  []  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29047.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.