• 石家庄停车位在线预约平台13


    HQL多表查询

    这里使用 多对多关系的用户表(user)和角色表(role)举例。
    对应的实体类
    User.java

    public class User {

        private int uid;
        private String uname;
        private int uage;
        private String usex;

        private Set<Role> roleSet=new HashSet<>();


        public Set<Role> getRoleSet() {
            return roleSet;
        }

        public void setRoleSet(Set<Role> roleSet) {
            this.roleSet = roleSet;
        }

        public int getUid() {
            return uid;
        }

        public void setUid(int uid) {
            this.uid = uid;
        }

        public String getUname() {
            return uname;
        }

        public void setUname(String uname) {
            this.uname = uname;
        }

        public int getUage() {
            return uage;
        }

        public void setUage(int uage) {
            this.uage = uage;
        }

        public String getUsex() {
            return usex;
        }

        public void setUsex(String usex) {
            this.usex = usex;
        }
    }

    Role.java

    public class Role {

        private int rid;
        private String rname;
        private int authority;
        private Set<User> userSet=new HashSet<User>();

        public int getRid() {
            return rid;
        }

        public void setRid(int rid) {
            this.rid = rid;
        }

        public String getRname() {
            return rname;
        }

        public void setRname(String rname) {
            this.rname = rname;
        }

        public int getAuthority() {
            return authority;
        }

        public void setAuthority(int authority) {
            this.authority = authority;
        }

        public Set<User> getUserSet() {
            return userSet;
        }

        public void setUserSet(Set<User> userSet) {
            this.userSet = userSet;
        }
    }

        内连接

    Query query=session.createQuery(“from User u inner join u.role”);
    List<User> list=query.list();

    返回的结果是数组

        迫切内连接

    Query query=session.createQuery(“from User u inner join fetch u.role”);
    List<User> list=query.list();


    返回的结果是对象

    左外连接

    Query query=session.createQuery(“from User u left outer join u.role”);
    List<User> list=query.list();

  • 相关阅读:
    软件项目“免坑”指南
    软件项目质量保证——编码规范
    从Web借鉴UI设计
    C#学习笔记——面向对象、面向组件以及类型基础
    关系数据库设计
    Winform开发框架之插件化应用框架实现
    桌面程序界面设计分享
    2-Bom
    1-简介
    测试
  • 原文地址:https://www.cnblogs.com/xiaohaigege666/p/12381756.html
Copyright © 2020-2023  润新知