TEST

customerlinkman数据表sql

create database hibernate character set=utf8;
use hibernate;

create table customer(
	cust_id bigint auto_increment  comment '主键',
    cust_name varchar(20) comment '客户名称',
    cust_source varchar(50) comment '客户信息来源',
    cust_industry varchar(25) comment '客户所属行业',
    cust_level varchar(2) comment '客户级别',
    cust_phone varchar(20) comment '固定电话',
    cust_mobile varchar(20) comment '移动电话',
    
    primary key (cust_id)
)Engine=InnoDB charset=utf8;


create table linkman(
	link_id bigint auto_increment comment '主键',
    link_name varchar(20) comment '联系人名称',
    link_gender char(2) comment '联系人性别',
    link_phone varchar(20) comment '联系人固定电话',
    kink_mobile varchar(20) comment '联系人手机',
    link_email varchar(20) comment '联系人邮箱',
    link_qq varchar(20) comment '联系人QQ',
    link_position varchar(30) comment '联系人职位',
    link_memo varchar(500) comment '联系人备注',
    link_cust_id bigint comment '外键',
    
    primary key(link_id),
    foreign key (link_cust_id) references customer(cust_id)
)Engine=InnoDB charset=utf8;
create database hibernatedemo character set=utf8;
use hibernatedemo;

create table department(
	dept_id int auto_increment comment '部门表主键',
    dept_name varchar(25) comment '部门名称',
    
    primary key(dept_id)
)Engine=InnoDB charset=utf8;

create table employee(
	emp_id int auto_increment comment '员工表主键',
    emp_name varchar(25) comment '员工名称',
   	salary double comment '工资',
    emp_dept_id int comment '员工表外键',
    
    primary key(emp_id),
    foreign key(emp_dept_id) references department(dept_id)
)Engine=InnoDB charset=utf8;

Hibernate中的映射一对多关系

t_customer和t_order的数据表

create database hibernatedemo character set=utf8;
use hibernatedemo;

create table t_customer(
    id int auto_increment comment '主键',
    name varchar(20) comment '顾客名称',
    gender char(2) comment '性别',
    primary key(id)
)Engine=InnoDB charset=utf8;

create table t_order(
    id int auto_increment comment '主键',
    orderno varchar(20) comment '订单的编号',
    product_name varchar(25) comment '产品名称',
    cust_id int comment '外键',

    primary key(id),
    foreign key(cust_id) references t_customer(id)
)Engine=InnoDB charset=utf8;

Customer与Order关系:(1-N)




<hibernate-mapping>
    <class name="learn.hibernate.Customer" table="t_customer">
        
        <id name="id" column="id">
            
            <generator class="native"/>
        id>
        
        <property name="name" column="name"/>
        <property name="gender" column="gender"/>

        
        <set name="orderSet">
            <key column="cust_id">key>
            <one-to-many class="learn.hibernate.Order"/>
        set>

    class>
hibernate-mapping>

Order与Customer关系:(N-1)




<hibernate-mapping>
    <class name="learn.hibernate.Order" table="t_order">
        
        <id name="id" column="id">
            
            <generator class="native"/>
        id>
        
        <property name="orderno" column="orderno"/>
        <property name="productName" column="product_name"/>

        
        <many-to-one name="customer" class="learn.hibernate.Customer" column="cust_id"/>
    class>
hibernate-mapping>

你可能感兴趣的:(Hibernate)