美文网首页
Spring Data Jpa 使用备忘

Spring Data Jpa 使用备忘

作者: 小马将过河 | 来源:发表于2019-03-24 22:15 被阅读0次

    springboot+SpringDataJpa用了很久了,有些东西不用时间长了也还是会忘。
    好记性不如烂笔头,这话是有道理的,所以用到什么就简单记录下,还是有好处的。

    1、Qquery不能使用limit关键字

    第一种方式:使用nativeQuery

    @Query("SELECT * FROM t_misaka m WHERE m.id>4 limit 0,2", nativeQuery=true) 
      Page<Misaka> search(Pageable pageable); 
    

    第二种方式:使用Page实现

    
    Pageable pageable = new PageRequest(1, 2, Direction.ASC, "name"); 
    Page<Misaka> misakaPage = misakaDao.search(pageable); 
    List<Misaka> misakaList = misakaPage.getContent(); 
    

    查询接口

    @Query("SELECT m FROM Misaka m WHERE m.id>4") 
      Page<Misaka> search(Pageable pageable); 
    

    注意:如果使用springboot2.x,上面的Pageable pageable = new PageRequest需要改成Pageable pageable = PageRequest.of();,里面参数一样。

    2、Jpa Repository里用@Query的查询结果集自定义接受实体

    直接上查询代码:

    @Query("SELECT d.smsDate AS smsDate , SUM(d.smsSendCount) AS smsSendCount , SUM(d.smsSendFailureCount) AS  smsSendFailureCount " +
            " FROM DashboardSms d" +
            " WHERE d.smsDate between :startDate AND :endDate " +
            " GROUP BY d.smsDate " +
            " ORDER BY d.smsDate ASC ")
    List<SmsCountSum> findAllBySmsDate(Date startDate, Date endDate);
    
    interface SmsCountSum {
        Date getSmsDate();
        Integer getSmsSendCount();
        Integer getSmsSendFailureCount();
    }
    

    调用处:

    List<SlaveDashboardSmsRepository.SmsCountSum> list = slaveDashboardSmsRepository.findAllBySmsDate(startDate, entDate);
    List<DashboardXYVo> smsChartData = list.stream().map(this::smsDataToVo).collect(Collectors.toList());
    private DashboardXYVo smsDataToVo(SlaveDashboardSmsRepository.SmsCountSum sms) {
        DashboardXYVo vo = new DashboardXYVo();
        vo.setX(DateUtil.date2str(sms.getSmsDate(), DateUtil.MONTH_DAY_FORMAT));
        vo.setY(String.valueOf(sms.getSmsSendCount()));
        return vo;
    }
    

    3、使用Specification查询

    一个常写的例子:

        public static Specification<DashboardAppSmsLogin> build(Date startDate, Date endDate) {
            return (root, criteriaQuery, builder) -> {
    
                Predicate predicate = builder.conjunction();
                try {
                    if (startDate != null) {
                        Predicate graterStartTime = null;
                        graterStartTime = builder.greaterThanOrEqualTo(root.get("smsDate"), DateUtil.formateData(startDate, DateUtil.DATE_FORMAT));
                        predicate = builder.and(predicate, graterStartTime);
                    }
                    if (endDate != null) {
                        Predicate lessEndTime = builder.lessThanOrEqualTo(root.get("smsDate"), DateUtil.formateData(endDate, DateUtil.DATE_FORMAT));
                        predicate = builder.and(predicate, lessEndTime);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                criteriaQuery.orderBy(builder.desc(root.get("appName")));
                return predicate;
    
            };
        }
    

    使用:

        Date yesterday = DateUtil.pastDate(new Date, 1);
        Specification<DashboardAppSmsLogin> spec = DashboardAppSmsSpecs.build(yesterday, new Date);
        List<DashboardAppSmsLogin> appSmsLogin = slaveDashboardAppSmsLoginRepository.findAll(spec);
    

    封装一层条件查的例子:
    包括equal、like、大于等于、小于等于、时间等条件。

        /**
         * 登录成功构建
         * @param query
         * @return
         */
        public static Specification<UserLoginLog> loginBuild(UserLoginLogQuery query) {
            return (root, criteriaQuery, builder) -> buildPredicate(root, builder, query);
        }
    
        /**
         * 登录失败构建
         * @param query
         * @return
         */
        public static Specification<UserLoginFailureLog> loginFailureBuild(UserLoginLogQuery query) {
            return (root, criteriaQuery, builder) -> buildPredicate(root, builder, query);
        }
    
    
        private static Predicate buildPredicate(Root root, CriteriaBuilder builder, UserLoginLogQuery query){
            Predicate predicate = builder.conjunction();
            if (!StringUtils.isEmpty(query.getAppId())) {
                Predicate equalMenuValue = builder.equal(root.get("appId"), query.getAppId());
                predicate = builder.and(predicate, equalMenuValue);
            }
            if (!StringUtils.isEmpty(query.getMobile())) {
                String likeMobile = "%" + query.getMobile() + "%";
                Predicate equalMenuValue = builder.like(root.get("mobile"), likeMobile);
                predicate = builder.and(predicate, equalMenuValue);
            }
            if (query.getStartLoginTime() != null) {
                Predicate graterStartTime = builder.greaterThanOrEqualTo(root.get("loginTime"), query.getStartLoginTime());
                predicate = builder.and(predicate, graterStartTime);
            }
            if (query.getEndLoginTime() != null) {
                Predicate lessEndTime = builder.lessThanOrEqualTo(root.get("loginTime"), query.getEndLoginTime());
                predicate = builder.and(predicate, lessEndTime);
            }
            return predicate;
        }
    

    调用就一样了。

    4、用@Modifying进行更新操作

        @Modifying
        @Query("update YhTask t set t.deleteFlag = '1' where t.taskId = :taskId")
        int logicDeleteTask(@Param("taskId") String taskId);
    

    5、JPA的Query里进行条件为空容错,时间格式化

    @Query("select u from YhUser u " +
                "where u.deleteFlag = '0' and u.leaderFlag = '0' " +
                "and u.fullName like concat('%',:createUserName,'%') " +
                "and (:platformId is null or :platformId is not null and u.platformId = :platformId) " +
                "and (:areaId is null or :areaId is not null and u.areaId = :areaId) " +
                " and DATE_FORMAT(s.firstLoginTime,'%Y-%m-%d')>=str_to_date(:startTime,'%Y-%m-%d') " +
                " and DATE_FORMAT(s.firstLoginTime,'%Y-%m-%d')<=str_to_date(:endTime,'%Y-%m-%d')" +
                "and u.haierUserId not in (" +
                "select t.createUserId from YhTask t where t.deleteFlag = '0' " +
                "and t.createTime between :startTime and :endTime)")
        List<YhUser> findUnsubmitedUserByTime(@Param("createUserName") String createUserName, @Param("platformId") String platformId, @Param("areaId") String areaId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
    
    

    6、多表级联的情况,条件查询示例

    比如,部门实体:

    @Data
    @Entity
    @Table(name = "t_user")
    public class User implements Serializable {
    
        private static final long serialVersionUID = 3046056270962780761L;
    
        /**
         * 用户id
         */
        @Id
        @GenericGenerator(name = "idGenerator", strategy = "uuid")
        @GeneratedValue(generator = "idGenerator")
        private String userId;
    
        @ManyToOne
        @JoinColumn(name = "dept_id")
        @NotFound(action = NotFoundAction.IGNORE)
        private Department department;
    

    部门实体:

    @Data
    @Entity
    @Table(name = "t_department")
    public class Department implements Serializable {
    
        private static final long serialVersionUID = 5415593855586815943L;
    
        @Id
        @GenericGenerator(name = "idGenerator", strategy = "uuid")
        @GeneratedValue(generator = "idGenerator")
        @Column(name = "dept_id")
        private String deptId;
    
        /**
         * 部门们称
         */
        private String deptName;
    
        /**
         * 部门代码
         */
        private String deptCode;
    
        /**
         * 父节点
         */
        private String parentId;
    

    根据多个部门id查询用户列表

          List<String> allDeptIds = findDeptIds(deptId);
          Page<HaierUser> users = haierUserRepository.findByDepartment_DeptIdIn(allDeptIds, pageable);
    

    findByDepartment_DeptIdIn方法呢?

    /**
         * 通过部门ID查询用户
         *
         * @param deptIds
         * @param pageable
         * @return
         */
        Page<HaierUser> findByDepartment_DeptIdIn(List<String> deptIds, Pageable pageable);
    

    中间一个下划线链接,就是这么简单。

    7、创建时间和更新时间自动处理

    @Entity  
    @Table(name="t_login_log")  
    @Data
    public class LoginLog {  
      @Id  
      @GenericGenerator(name="UUIDGENERATE",strategy="uuid2")  
      @GeneratedValue(generator="UUIDGENERATE")  
      @Column(name="id",length=36)  
      private String id;
      
      @Column(name="create_time, updatable = false)  
      @Temporal(TemporalType.TIMESTAMP)  
      @org.hibernate.annotations.CreationTimestamp   
      private Date createTime;
       
      @Column(name="update_time")  
      @Temporal(TemporalType.TIMESTAMP)  
      @org.hibernate.annotations.UpdateTimestamp
      private Date updateTime;   
    
    

    8、实体上常用的一些注解

    时间格式化

        @JsonFormat(pattern = DateUtil.TIME_FORMAT, timezone = "GMT+8")
        @Column(updatable = false)
        private Date createTime;
    

    在json结构中忽略

        /**
         * 删除标志,1:删除,0:未删除
         */
        @JsonIgnore
        private Boolean deleteFlag = false;
    

    插入/更新时自动赋值

        @PrePersist
        public void PrePersist() {
            this.createTime = new Date();
        }
    
      @PreUpdate
        public void PreUpdate() {
            this.updateTime = new Date();
        }
    

    @Temporal(TemporalType.DATE)
    在页面端取值:2016--09--28
    @Temporal(TemporalType.TIME)
    在页面端取值:15:50:30
    @Temporal(TemporalType.TIMESTAMP)
    在页面端取值:2016-09-28 15:52:32:000
    @Transient
    Hibernate实体类注解中忽略某些字段的映射关系

    9、自定义Repository实现查询

    import org.springframework.stereotype.Repository;
    
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    import java.util.List;
    
    /**
     * 推送类型统计
     */
    @Repository
    public class MessageStatisticRepository {
    
        @PersistenceContext
        private EntityManager entityManager;
    
        /**
         * 统计每个推送类型的推送消息数量
         * @param userId
         * @param search
         * @return
         */
        public List<Object[]>  findMessageTypeCont(String userId, String search){
            String sql = "SELECT t.id,t.title,t.icon,p.num FROM t_message_type AS t INNER JOIN  " +
                         "(" +
                            "SELECT type,COUNT(*) AS num FROM t_message_push " +
                            "WHERE (title LIKE :search OR content LIKE :search) AND state <> 3 AND receive_user_id=:userId " +
                            "GROUP BY type" +
                         ") AS p " +
                         " on t.id = p.type WHERE t.delete_flag=0 ORDER BY t.order ASC";
            Query query = entityManager.createNativeQuery(sql);
            query.setParameter("search", '%' +search + '%');
            query.setParameter("userId", userId);
            return query.getResultList();
        }
    
    }
    

    获取到的结果是List的Object数组,里面的值需要解析Object获取。

       public static MessageTypeVo toMessageTypeVo(Object[] data){
           MessageTypeVo messageType = new MessageTypeVo();
           messageType.setId((String) data[0]);
           messageType.setTitle((String) data[1]);
           messageType.setIcon((String) data[2]);
           messageType.setCount((BigInteger) data[3]);
           return messageType;
       }
    
       List<Object[]> rows = messageStatisticRepository.findMessageTypeCont(userId, keywords);
       List<MessageTypeVo> messageTypes = rows.stream().map(MessageTypeVo::toMessageTypeVo).collect(Collectors.toList());
    

    上面的查询如果不返回Object,也可以设置返回成map,只需要在查询前设置ResultTransformer即可:

    query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> resultLit = query.getResultList();
    

    10、多表级联查询自定义返回结果

    首先定义一个结果集的接口类,

    public interface HotelSummary {
        City getCity();
        String getName();
        Double getAverageRating();
        default Integer getAverageRatingRounded() {
            return getAverageRating() == null ? null : (int) Math.round(getAverageRating());
        }
    }
    

    查询的方法返回类型设置为新创建的接口

    @Query("select h.city as city, h.name as name, avg(r.rating) as averageRating "
            - "from Hotel h left outer join h.reviews r where h.city = ?1 group by h")
    Page<HotelSummary> findByCity(City city, Pageable pageable);
    
    @Query("select h.name as name, avg(r.rating) as averageRating "
            - "from Hotel h left outer join h.reviews r  group by h")
    Page<HotelSummary> findByCity(Pageable pageable);
    

    使用

    Page<HotelSummary> hotels = this.hotelRepository.findByCity(new PageRequest(0, 10, Direction.ASC, "name"));
    for(HotelSummary summay:hotels) {
        System.out.println("Name" +summay.getName());
    }
    

    碰到的错误

    版本问题

    1、问题和现状
    配置一个Hibernate的OneToMany的映射,想要达到级联保存和级联查询,查主体时将对应的many的列表页查出来,但是在如下的配置后,
    主表:

    @Data
    @Entity
    @Table(name = "t_patient")
    public class Patient {
        @Id
        @GenericGenerator(name = "idGenerator", strategy = "uuid")
        @GeneratedValue(generator = "idGenerator")
        @Column(name = "patient_id", length = 40)
        private String patientId;
    
        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        @JoinColumn(name = "patient_id")
        private List<PatientAllergicHistory> patientAllergicHistory = new LinkedList<>();
    }
    

    子表:

    @Data
    @Entity
    @Table(name = "t_patient_allergic_history")
    public class PatientAllergicHistory {
        @Id
        @GenericGenerator(name = "idGenerator", strategy = "uuid")
        @GeneratedValue(generator = "idGenerator")
        @Column(name = "id")
        private Long id;
    
        /** 患者id */
        @Column(name = "patient_id")
        private String patientId;
    }
    

    查询时抛出异常

    org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.hczt.xhminiapp.db.entity.Patient.patientContacts, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.hczt.xhminiapp.db.entity.Patient.patientContacts, could not initialize proxy - no Session (through reference chain: com.hczt.xhminiapp.common.bean.RtnResult["data"]->com.hczt.xhminiapp.db.entity.Patient["patientContacts"])
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:296)
        at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:103)
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:290)
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:180)
        at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.hczt.xhminiapp.db.entity.Patient.patientContacts, could not initialize proxy - no Session (through reference chain: com.hczt.xhminiapp.common.bean.RtnResult["data"]->com.hczt.xhminiapp.db.entity.Patient["patientContacts"])
        at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394)
        at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:353)
        at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
        at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
        at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913)
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:287)
        ... 47 common frames omitted
    Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.hczt.xhminiapp.db.entity.Patient.patientContacts, could not initialize proxy - no Session
        at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:597)
        at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:216)
        at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:160)
        at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:287)
        at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:97)
        at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
        ... 56 common frames omitted
    

    2、原因和解决
    该异常在https://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags上找到了答案(staticOverFlow还是很强大的)。

    I think a newer version of hibernate (supporting JPA 2.0) should handle this. But otherwise you can work it around by annotating the collection fields with: @LazyCollection(LazyCollectionOption.FALSE),Remember to remove the fetchType attribute from the @*ToMany annotation.

     @OneToMany(cascade = CascadeType.ALL)
     @LazyCollection(LazyCollectionOption.FALSE)
     @JoinColumn(name = "patient_id")
     private List<PatientAllergicHistory> patientAllergicHistory = new LinkedList<>();
    

    正常的控制台日志应该是这样的,主查询完了以后,开启子查询

    10:26:29.920 [http-nio-8085-exec-10] INFO  p6spy - 10:26:29|1|SELECT 1 FROM DUAL
    10:26:29.932 [http-nio-8085-exec-10] INFO  p6spy - 10:26:29|4|select patient0_.patient_id as patient_1_3_0_, patient0_.create_time as create_t2_3_0_, patient0_.deleted as deleted3_3_0_, patient0_.first_diagnose_date as first_di4_3_0_, patient0_.first_injection_date as first_in5_3_0_, patient0_.gender as gender6_3_0_, patient0_.height as height7_3_0_, patient0_.mobile as mobile8_3_0_, patient0_.name as name9_3_0_, patient0_.nick_name as nick_na10_3_0_, patient0_.openid as openid11_3_0_, patient0_.passive_smoking as passive15_3_0_, patient0_.self_smoking as self_sm12_3_0_, patient0_.unionid as unionid13_3_0_, patient0_.weight as weight14_3_0_, sysdict1_.id as id1_6_1_, sysdict1_.code as code2_6_1_, sysdict1_.create_time as create_t3_6_1_, sysdict1_.deleted as deleted4_6_1_, sysdict1_.group_code as group_co5_6_1_, sysdict1_.name as name6_6_1_, sysdict1_.parent_id as parent_i7_6_1_, sysdict1_.sort as sort8_6_1_, sysdict1_.type as type9_6_1_, sysdict1_.update_time as update_10_6_1_ from t_patient patient0_ left outer join t_sys_dict sysdict1_ on patient0_.passive_smoking=sysdict1_.id where patient0_.patient_id='111'
    10:26:29.940 [http-nio-8085-exec-10] INFO  p6spy - 10:26:29|2|select patientcon0_.patient_id as patient_6_5_0_, patientcon0_.id as id1_5_0_, patientcon0_.id as id1_5_1_, patientcon0_.address as address2_5_1_, patientcon0_.gender as gender3_5_1_, patientcon0_.mobile as mobile4_5_1_, patientcon0_.name as name5_5_1_, patientcon0_.patient_id as patient_6_5_1_, patientcon0_.relation as relation7_5_1_, sysdict1_.id as id1_6_2_, sysdict1_.code as code2_6_2_, sysdict1_.create_time as create_t3_6_2_, sysdict1_.deleted as deleted4_6_2_, sysdict1_.group_code as group_co5_6_2_, sysdict1_.name as name6_6_2_, sysdict1_.parent_id as parent_i7_6_2_, sysdict1_.sort as sort8_6_2_, sysdict1_.type as type9_6_2_, sysdict1_.update_time as update_10_6_2_ from t_patient_contacts patientcon0_ left outer join t_sys_dict sysdict1_ on patientcon0_.relation=sysdict1_.id where patientcon0_.patient_id='111'
    10:26:29.945 [http-nio-8085-exec-10] INFO  p6spy - 10:26:29|1|select patientall0_.patient_id as patient_5_4_0_, patientall0_.id as id1_4_0_, patientall0_.id as id1_4_1_, patientall0_.gmxby as gmxby2_4_1_, patientall0_.gmxpy as gmxpy3_4_1_, patientall0_.main as main4_4_1_, patientall0_.patient_id as patient_5_4_1_, patientall0_.swgm as swgm6_4_1_, patientall0_.ybgmz as ybgmz7_4_1_, patientall0_.zqgxc as zqgxc8_4_1_ from t_patient_allergic_history patientall0_ where patientall0_.patient_id='111'
    10:26:29.947 [http-nio-8085-exec-10] INFO  p6spy - 10:26:29|0|
    

    推荐阅读

    Security源码分析

    相关文章

      网友评论

          本文标题:Spring Data Jpa 使用备忘

          本文链接:https://www.haomeiwen.com/subject/wpeyvqtx.html