sql代码

自定义返回结果

package com.cdp.ecosaas.coredb.uua.sync.vo;

import java.io.Serializable;

public class UuaUserNotifyTemp implements Serializable {

    /**
*
*/
private static final long serialVersionUID = 1L; private String id; private String sysCode; private String sysName; private String idNumber; private String email; private String phone; private String tenantId; private String isAuto; private String isEmail; private String isMobile; private String emailLang; private String msmLang; private String mailNotify; private String mobileNotify; private String state; public String getIdNumber() {
return idNumber;
} public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public String getPhone() {
return phone;
} public void setPhone(String phone) {
this.phone = phone;
} public String getTenantId() {
return tenantId;
} public void setTenantId(String tenantId) {
this.tenantId = tenantId;
} public String getIsAuto() {
return isAuto;
} public void setIsAuto(String isAuto) {
this.isAuto = isAuto;
} public String getIsEmail() {
return isEmail;
} public void setIsEmail(String isEmail) {
this.isEmail = isEmail;
} public String getIsMobile() {
return isMobile;
} public void setIsMobile(String isMobile) {
this.isMobile = isMobile;
} public String getEmailLang() {
return emailLang;
} public void setEmailLang(String emailLang) {
this.emailLang = emailLang;
} public String getMsmLang() {
return msmLang;
} public void setMsmLang(String msmLang) {
this.msmLang = msmLang;
} public String getMailNotify() {
return mailNotify;
} public void setMailNotify(String mailNotify) {
this.mailNotify = mailNotify;
} public String getMobileNotify() {
return mobileNotify;
} public void setMobileNotify(String mobileNotify) {
this.mobileNotify = mobileNotify;
} public String getState() {
return state;
} public void setState(String state) {
this.state = state;
} public String getSysCode() {
return sysCode;
} public void setSysCode(String sysCode) {
this.sysCode = sysCode;
} public String getSysName() {
return sysName;
} public void setSysName(String sysName) {
this.sysName = sysName;
} public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public UuaUserNotifyTemp(String id, String sysCode, String sysName, String idNumber, String email, String phone,
String tenantId, String isAuto, String isEmail, String isMobile, String emailLang, String msmLang,
String mailNotify, String mobileNotify, String state) {
super();
this.id = id;
this.sysCode = sysCode;
this.sysName = sysName;
this.idNumber = idNumber;
this.email = email;
this.phone = phone;
this.tenantId = tenantId;
this.isAuto = isAuto;
this.isEmail = isEmail;
this.isMobile = isMobile;
this.emailLang = emailLang;
this.msmLang = msmLang;
this.mailNotify = mailNotify;
this.mobileNotify = mobileNotify;
this.state = state;
} }

sql代码

@Query(value = "SELECT new com.cdp.ecosaas.coredb.uua.sync.vo.UuaUserNotifyTemp(uu.id,ue.sysCode,ue.sysName,uu.idNumber,uu.email,uu.phone,ue.tenantId,unc.isAuto,unc.isEmail,unc.isMobile,unc.emailLang,unc.msmLang, uu.mailNotify, uu.mobileNotify, uu.state) FROM UuaUser uu LEFT JOIN UuaUserExtsysRef uuer on uu.id = uuer.id.userId LEFT JOIN UuaExtsy ue on ue.id = uuer.id.extsysId LEFT JOIN UuaNotifyConfig unc ON unc.tenantId = ue.tenantId where unc.isAuto = 1 and (uu.state = 0 or uu.state is null) and (uu.mailNotify = 0 or uu.mailNotify is null) and (uu.mobileNotify = 0 or uu.mobileNotify is null) ")
List<UuaUserNotifyTemp> findNotifyUserTemp();

注意点 1先把原来sql写好 保证能把执行,自定义返回结果只支持hql语句,不支持原生sql

2表连接的时候注意使用的对象的属性连接,比如属性是id,数据库字段是_id,这里用的是id,如果sql能执行,hql也一定能执行

3注意使用高版本的hibernate  

<hibernate.version>5.2.12.Final</hibernate.version>

之前大家说的什么hql leftjoin  不识别 on 是版本的问题

4自定义返回结果要跟hql写的字段顺序对应。


建议如果使用jpa 还是推荐把表之间关联关系维护好,不要走这用歪路子。特别是加载策略以及级联关系。不要都扔一个all就完事了

jpa多表leftjoin 查询,自定义返回结果的更多相关文章

  1. JPA 多表分页查询

    业务场景:大学生毕业后统计毕业去向.学生实体和毕业去向实体一对一关系. 实体: @Entity @Data @Table(name = "t_s_student") public ...

  2. JPA的多表复杂查询

    转 JPA的多表复杂查询:详细篇 原文链接: https://mp.weixin.qq.com/s/7J6ANppuiZJccIVN-h0T3Q 2017-11-10 从小爱喝AD钙  最近工作中由于 ...

  3. Mybatis多表关联查询字段值覆盖问题

    一.错误展示 1.首先向大家展示多表关联查询的返回结果集 <resultMap id="specialdayAndWorktimeMap type="com.hierway. ...

  4. JPA使用nativequery多表关联查询返回自定义实体类

    本文为JPA的学习采坑,如有问题欢迎指正. JPA官方推荐的多表关联查询使用不便,接触的有些项目可能会使用JPA 做简单查询,Mybaits做复杂查询.所以想要寻找一种好用的解决方案. JPA多表关联 ...

  5. Spring Data JPA 查询结果返回至自定义实体

    本人在实际工作中使用Spring Data Jpa框架时,一般查询结果只返回对应的Entity实体.但有时根据实际业务,需要进行一些较复杂的查询,比较棘手.虽然在框架上我们可以使用@Query注解执行 ...

  6. MyBatis 多表联合查询及优化 以及自定义返回结果集

    下面就来说一下 mybatis 是通过什么来实现多表联合查询的.首先看一下表关系,如图: 这 里,我已经搭好了开发的环境,用到的是 SpringMVC + Spring + MyBatis,当然,为了 ...

  7. Spring Hibernate JPA 联表查询 复杂查询(转)

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  8. Spring Hibernate JPA 联表查询 复杂查询

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  9. Linq to Sql:N层应用中的查询(上) : 返回自定义实体

    原文:Linq to Sql:N层应用中的查询(上) : 返回自定义实体 如果允许在UI层直接访问Linq to Sql的DataContext,可以省去很多问题,譬如在处理多表join的时候,我们使 ...

随机推荐

  1. $id(id)函数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 万兴神剪手 Wondershare Filmora v9.2.11.6 简体中文版

    目录 1. 介绍 2. 简体中文9.2.1.10汉化版下载 3. 安装和激活说明 1. 介绍 万兴神剪手 Filmora 是一款界面简洁时尚.功能强大的视频编辑软件,它是深圳万兴科技公司近年来的代表作 ...

  3. spring boot基础学习教程

    Spring boot 标签(空格分隔): springboot HelloWorld 什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新 ...

  4. Linux基础命令练习题(附答案)

    1.分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处? [root@localhost ~]# cat ...

  5. laravel-admin Field type [editor] does not exist.

    把App/admin中的bootstrap.php 里边的Encore\Admin\Form::forget(['map', 'editor']);注释掉就行了 解决网址:http://tieba.b ...

  6. bat 感想

    用bat做了个跨版本更新包的生成脚本,由于之前都是写一些很简单bat,或者python里使用windows命令,所以纯用bat做这个东西,还是有点复杂的. 过程中遇到很多问题,主要是参数太多,变量的使 ...

  7. 2019.10.17 CCSP自闭打铜

    很幸运被珠姐第二次抓过来参加CCSP(第二次看xmk夺冠),不过今年的题目还是那么让人心肌梗塞呢(听题解的时候基本都能听懂也算是进步了8). 比赛前一天晚上躺在宾馆里,做梦梦见自己在打比赛,局面应该是 ...

  8. 关于 php for zookeeper

    原文:Distributed application in PHP with Apache Zookeeper 地址:http://systemsarchitect.net/distributed-a ...

  9. php set_magic_quotes_runtime() 函数过时解决方法

    PHP5.3中 bool set_magic_quotes_runtime ( bool $new_setting )函数过时.把函数: set_magic_quotes_runtime($newse ...

  10. django middleware介绍

    Middleware Middleware是一个镶嵌到django的request/response处理机制中的一个hooks框架.它是一个修改django全局输入输出的一个底层插件系统. 每个中间件 ...