zoukankan      html  css  js  c++  java
  • hibernate一对多关联

    实体之间有三种关系:

    1.一对一

    2.一对多

    3.多对一

    一对多

    goods类

    package entity;
    /*
    * 货物表
    * */
    public class goods {
    private int gid;
    private long gnum;
    private inventory inv;
    public int getGid() {
    return gid;
    }
    public void setGid(int gid) {
    this.gid = gid;
    }
    public long getGnum() {
    return gnum;
    }
    public void setGnum(long gnum) {
    this.gnum = gnum;
    }
    public inventory getInv() {
    return inv;
    }
    public void setInv(inventory inv) {
    this.inv = inv;
    }


    }

    配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
    <class name="entity.goods" table="goods">
    <id name="gid" column="gid">
    <generator class="native"/>
    </id>
    <property name="gnum" column="gnum"></property>
    <many-to-one name="inv" column="igid" class="entity.inventory"></many-to-one>

        <!--

        <many-to-one>标签

            name    :关联对象的属性的名称.

            column  :表中的外键名称.

            class   :关联对象类的全路径

        -->

    </class>
    </hibernate-mapping>

    inventory类

    package entity;

    import java.util.HashSet;

    import java.util.Set;

    /*

     * 清单表

     * */

    public class inventory {

    private int iid;

    private String iname;

    //private int igid;

    private Set<goods> goodses=new HashSet<goods>();

    public int getIid() {

    return iid;

    }

    public void setIid(int iid) {

    this.iid = iid;

    }

    public String getIname() {

    return iname;

    }

    public void setIname(String iname) {

    this.iname = iname;

    }

    //public int getIgid() {

    //return igid;

    //}

    //public void setIgid(int igid) {

    //this.igid = igid;

    //}

    public Set<goods> getGoodses() {

    return goodses;

    }

    public void setGoodses(Set<goods> goodses) {

    this.goodses = goodses;

    }

    }

    配置

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE hibernate-mapping PUBLIC 

        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

        <hibernate-mapping>

        <class name="entity.inventory" table="inventory">

        <id name="iid" column="iid">

        </id>

        <property name="iname" column="iname"></property>

        <!-- <property name="igid" column="igid"></property> -->

       

        <set name="goodses">

        <key column="igid"></key>

        <one-to-many class="entity.goods"/>

        </set>

        </class>

        

        </hibernate-mapping>

        <!--

        <many-to-one>标签

            name    :关联对象的属性的名称.

            column  :表中的外键名称.

            class   :关联对象类的全路径

        -->

  • 相关阅读:
    1、Java语言概述与开发环境——Java程序运行机制
    1、Java语言概述与开发环境——JDK的安装与环境变量的配置
    针孔成像模型
    anconda下安装opencv
    用Navicat Prenium12连接Oracle数据库(oracle11g版本)时报错ORA-28547:connection to server failed,probable Oracle Net admin error.解决办法
    JQueryEsayUI的datagrid分页
    java中String和int的互相转化
    js页面刷新
    oracle的正则表达式
    EL表达式中,param和requestScope的区别
  • 原文地址:https://www.cnblogs.com/longlinxie/p/5628333.html
Copyright © 2011-2022 走看看