zoukankan      html  css  js  c++  java
  • hibernate关联查询

     所谓关联查询即查询某个表的时候会连带查询出相关联的表的数据。

    1) 一对一:例如一个员工表与员工详细表的对应关系

    2) 一对多:一张表的一条记录可以对应另外一张表的多条记录。比如部门与员工的关系。

    3) 多对一:与一对多相反,例如员工表与部门表之间的关系。通过外键来维护。

    4) 多对多:例如一个员工有多个角色,一个角色 可以对应多个员工。多对多通常需要一张中间表来维护关联关系。

    一、在创建过程中要用到的表和序列如下:

    -- 部门表
    create table t_dept(
    id number(11) primary key ,
    deptcode varchar2(20) unique not null ,
    deptname varchar2(50) not null
    );
    -- 管理员表
    create table t_admin(
    id number(11) primary key ,
    account varchar2(50) unique not null ,
    password varchar2(20) not null ,
    deptid number(11) references t_dept(id)
    );
    -- 角色表
    create table t_role(
    id number(11) primary key ,
    rolecode varchar2(50) not null,
    rolename varchar2(50) not null ,
    status char(1) default '0'
    );
    -- 用户角色关系表(生成实体类时,此表不需要操作)
    create table t_user_role(
    roleid number(11) references t_role(id) not null ,
    userid number(11) references t_admin(id) not null
    );
    -- 用户详情表
    create table t_user_detail(
    id number(11) primary key ,
    addr varchar2(200),
    education varchar2(20)
    );

    create sequence seq_t_admin;
    create sequence seq_t_role;
    create sequence seq_t_dept;
    二、一些java文件和相对于的映射文件的配置如下所示:
    ①一对一关联:

    ②一对多关联:一对多,不配admin的原因是,我们现在只是单向操作,只通过部门来寻找部门的人员信息,而没有通过人员来查找部门,但是到后面会配;

    ③多对一:

    ④多对多:















  • 相关阅读:
    CISCO设备的一些硬件知识
    引用 DOS查QQ好友IP(另附入侵方法)
    【转】端口入侵常用工具分析
    修改CentOS默认yum源为国内yum镜像源
    使用Runtime类运行本地可执行文件
    英汉小词典 java随机存取文件流应用 version1.0
    8086/8088汇编过程练习 实现登录界面及其验证
    批处理伪加密
    快速启动中【显示桌面】的还原方法
    批处理字符串偏移指针
  • 原文地址:https://www.cnblogs.com/xie-qi/p/12873083.html
Copyright © 2011-2022 走看看