jpa/hibernate @onetomany 使用left join 添加多条件,可以使用过滤器filters (with-clause not allowed on fetched associations; use filters异常信息)
package com.ipinyou.mip.dataAsset.campaignManagement.entity; import com.ipinyou.mip.utils.NumberUtils;
import com.ipinyou.mip.utils.StringHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.builder.HashCodeExclude;
import org.hibernate.annotations.Filter; import javax.persistence.*; import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.Set; import static javax.persistence.FetchType.EAGER;
import static javax.persistence.FetchType.LAZY; @Data
@Entity
@Table(name = "campaign_dashboard_dimension")
@ToString
@EqualsAndHashCode
public class CampaignDashboardDimensionDo { @Id
private Long id; @Transient
private Double impRate = 1.0;
@Column(name = "3_reach")
private Double reach3;
@Column(name = "1_reach")
private Double reach1;
private Long campaignId;
@OneToMany(fetch = LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "campaign_dashboard_dimension_id")
@org.hibernate.annotations.OrderBy(clause = "imp desc")
@Filter(name = "dimension",condition = "dimension_type=:dimension ")
private Set<CampaignDashboardDimensionDetailDo> campaignDashboardDimensionDetailDo = new HashSet<>(); }
one
package com.ipinyou.mip.dataAsset.campaignManagement.entity; import com.ipinyou.mip.utils.NumberUtils;
import com.ipinyou.mip.utils.StringHelper;
import lombok.Data;
import lombok.ToString;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.Where; import javax.persistence.*;
import java.text.DecimalFormat; import static javax.persistence.FetchType.EAGER; @Data
@Entity
@Table(name = "campaign_dashboard_dimension_detail")
@ToString
@FilterDef(name="dimension", parameters=@ParamDef(name="dimension",type="java.lang.String"))
public class CampaignDashboardDimensionDetailDo {
@Id
private Long id;
private Long version;
private java.sql.Timestamp lastModified;
private String removed; private Long imp;
private Double reachRate;
private String dimensionName;
private String dimensionType;
private Long uv;
private Long click;
private Double ta = 0.0; @Transient
private Double impRate;
@Transient
private Double diffTa;
@Transient
private Double diffReach3 = 0.0;
@Transient
private Double targetTa = 0.0;
@Transient
private Double targetReach3 = 0.0; }
many
public List<CampaignDashboardDimensionDo> getCategoryData(List<String> displayType, String dimension, String source, Long campaignId) { List<CampaignDashboardDimensionDo> resultList=new ArrayList<>();
if (displayType==null||displayType.isEmpty()){
return resultList;
} for (String type:displayType ){
StringBuilder sb = new StringBuilder();
sb.append("select cdd from CampaignDashboardDimensionDo as cdd left join fetch cdd.campaignDashboardDimensionDetailDo as cddd where cdd.campaignId=:campaignId and cdd.source=:source" +
" and cdd.logDate=(select max(logDate) from CampaignDashboardDimensionDo where campaignId=:campaignId and source=:source and displayType=:type) and cdd.displayType=:type");
Filter filter = entityManager.unwrap(Session.class).enableFilter("dimension");
filter.setParameter("dimension",dimension);
TypedQuery<CampaignDashboardDimensionDo> query = entityManager.createQuery(sb.toString(), CampaignDashboardDimensionDo.class);
query.setParameter("type",type);
query.setParameter("source", source);
query.setParameter("campaignId", campaignId);
List<CampaignDashboardDimensionDo> list = query.getResultList();
Set<CampaignDashboardDimensionDo> set=new HashSet<>(list);
resultList.addAll(set);
} return resultList; }
查询代码
jpa/hibernate @onetomany 使用left join 添加多条件,可以使用过滤器filters (with-clause not allowed on fetched associations; use filters异常信息)的更多相关文章
- JPA(Hibernate) @OneToMany 两种例子
环境:Spring Data Jpa,hibernate或者其他jpa实现也是一样的:Spring Boot 场景:User和Role,一个User要对应多个Role. 第一种方式,没有中间关系表,直 ...
- Spring Data Jpa(Hibernate) OneToMany
这个其实非常简单.假设有topic 和 subscriber两个实体类,不考虑关联关系,则连个类的代码如下: /** * Created by csonezp on 2017/8/31. */ @En ...
- Hibernate @OneToMany等注解设置查询过滤条件等
1.如实体PdOrg对象中有users对象,数据库user表有字段DEL_FLAG(0:删除:1:未删除): private List<User> users= new ArrayList ...
- hibernate @OneToMany等注解设置查询过滤条件
如实体PdOrg对象中有users对象,数据库user表有字段DEL_FLAG(0:删除:1:未删除): private List<User> users= new ArrayList&l ...
- Spring Boot 2.x 之 Spring Data JPA, Hibernate 5
1. Spring Boot常用配置项 基于Spring Boot 2.0.6.RELEASE 1.1 配置属性类 spring.jpa前缀的相关配置项定义在JpaProperties类中, 1.2 ...
- Spring + SpringMVC + Druid + JPA(Hibernate impl) 给你一个稳妥的后端解决方案
最近手头的工作不太繁重,自己试着倒腾了一套用开源框架组建的 JavaWeb 后端解决方案. 感觉还不错的样子,但实践和项目实战还是有很大的落差,这里只做抛砖引玉之用. 项目 git 地址:https: ...
- 五、spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate
1.pom添加依赖 <!-- spring data jpa,会注入tomcat jdbc pool/hibernate等 --> <dependency> <group ...
- Spring Boot + Jpa(Hibernate) 架构基本配置
本文转载自:https://blog.csdn.net/javahighness/article/details/53055149 1.基于springboot-1.4.0.RELEASE版本测试 2 ...
- SpringBoot + Jpa(Hibernate) 架构基本配置
1.基于springboot-1.4.0.RELEASE版本测试 2.springBoot + Hibernate + Druid + Mysql + servlet(jsp) 一.maven的pom ...
随机推荐
- c++11の简单线程管理
1.简单的例子 #include "stdafx.h" #include <iostream> #include <thread> void functio ...
- Java MultipartFile 使用记录
private void file(String path,MultipartFile file){ String separator = "/"; String originFi ...
- SQL Server的JOIN是支持使用小括号修改执行顺序的
假如现在我们的SQL Server数据库中有三个表:[T_A].[T_B]和[T_C],它们的建表语句如下: --建表语句[T_A] CREATE TABLE [dbo].[T_A]( [ID_A] ...
- 单机部署 ELK
对于一个体量不大的系统,运行在单机上的 ELK 就足以胜任日志的处理任务了.本文介绍如何在单台服务器上安装并配置 ELK(elalasticsearch + logstash + kibana),并最 ...
- 关于表单元素的name及HTML中的id
这种在上高级WEB课时,老师为表单元素赋了name值,之后直接在JS中使用该值而不需要使用document.get...来获取了,例: <!DOCTYPE html> <html&g ...
- echarts报表显示%+没有0
function showTablegroup(page) { var series; $.ajax({ type:'post', url:"<%=basePath%>flowA ...
- Python的各种推导式合集
推导式的套路 之前我们已经学习了最简单的列表推导式和生成器表达式.但是除此之外,其实还有字典推导式.集合推导式等等. 下面是一个以列表推导式为例的推导式详细格式,同样适用于其他推导式. variabl ...
- Java的selenium代码随笔(1)
package ShareClass; import java.awt.AWTException;import java.awt.Robot;import java.awt.Toolkit;impor ...
- 通过JS获取URL链接带的参数
1 /** 2 * 获取URL参数的方法 3 */ 4 $.extend({ //以便于通过$引用该方法 5 getUrlVars : function() { //获取多个参数数组 6 var va ...
- ABP中的拦截器之AuditingInterceptor
在上面两篇介绍了ABP中的ValidationInterceptor之后,我们今天来看看ABP中定义的另外一种Interceptor即为AuditingInterceptor,顾名思义就是一种审计相关 ...