하루하나
close
프로필 배경
프로필 로고

하루하나

  • ALL (217)
    • 쿠베플로우 kubeflow (1)
    • React Native (1)
      • Expo (1)
    • Programming (187)
      • spring+jwt+react (4)
      • wordpress (3)
      • Vultr (1)
      • Flutter (3)
      • Vue-project (1)
      • Vue-tip (17)
      • AngularJS (12)
      • Bootstrap (2)
      • Book (1)
      • CentOS (5)
      • Code (0)
      • Css (13)
      • Docker (7)
      • Eclipse (1)
      • Freemarker (1)
      • Git (9)
      • Front-End (6)
      • Error (7)
      • Gulp.js (0)
      • Java (12)
      • Python (5)
      • Javascript (19)
      • JPA (5)
      • jQuery (2)
      • Mac (6)
      • MySql (4)
      • Springboot (21)
      • Springboot-blog (0)
      • Daily (1)
      • Springboot-tip (3)
      • Spring (1)
      • Thymeleaf (1)
      • Tomcat (1)
      • Typescript (3)
      • Tool (5)
      • Sql (1)
      • prisma (1)
      • react (1)
    • Life (14)
      • Review (0)
      • Tip (3)
      • 리뷰 (8)
      • 부동산 (2)
  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

[JPA] 원하는 내용만 가져오기

JPA로 조회를 하다보면 연관관계에 데이터를 모두 가져오다 보니 때때로 노출하고 싶지 않은 데이터도 가져오게 된다. 그럴때 쓰는 방법 소스는 이전글을 참조 2019/03/20 - [JPA] - [JPA] manytoone n+1 문제? 예를 들어 아래와 같은 member entity를 가지고 있다고 할때 @Entity @Getter @Setter public class Member { @Id @GeneratedValue private Long id; private String name; private String phone; private String address; @ManyToOne @JoinColumn(name="team_id") private Team team; } api에는 id와 name만 내..

  • format_list_bulleted Programming/JPA
  • · 2019. 3. 26.
  • textsms

[JPA] manytoone n+1 문제?

JPA에서 @manytoone으로 다른 entity와 join했을 경우 list를 출력하면, 리스트를 한번 조회하고, join column의 id 수만큼 다시 select를 하게된다. Member.java@Entity @Getter @Setter public class Member { @Id @GeneratedValue private Long id; private String name; @ManyToOne @JoinColumn(name="team_id") private Team team; }MemberRepo.javapublic interface MemberRepo extends JpaRepository {}Team.java@Entity @Getter @Setter public class Team { @..

  • format_list_bulleted Programming/JPA
  • · 2019. 3. 20.
  • textsms

[Error] Parameter value [2017/08/22] did not match expected type [java.util.Date (n/a)]

entity에 Date형인 orderDate가 존재한다고 했을 때 Specification을 이용한 between 검색을 하는 방법이다. 물론 interface에서 바로 해도 되지만 복합적으로 조건을 처리해줘야할 때 Specification은 유용하게 사용된다. 파라미터로 fromDt="2017/08/23" , toDt="2017/08/23" 받고 단순히 아래와 같이 했을 때 제목과 같은 오류가 났다. public static Specification betweenDate(String fromDt, String toDt) {return (root, query, cb) -> {if (fromDt.equals("") && toDt.equals(""))return null;return cb.between(ro..

  • format_list_bulleted Programming/JPA
  • · 2017. 8. 23.
  • textsms

[JPA/error] Could not write JSON: No default constructor for entity:

Problem Entity 데이터 조회 중 아래와 같은 오류 발생 Could not write JSON: No default constructor for entity: Solution 말그대로 생성자가 없어서 생기는 오류. 해당 Entity에 기본 생성자를 생성해준다.

  • format_list_bulleted Programming/JPA
  • · 2017. 6. 15.
  • textsms

[JPA/error] org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:

Problem. JPA @ManyToMany Entity에 Save 처리 중 아래와 같은 오류 발생 org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Solution 맵핑 어노테이션에 cascade=CascadeType.ALL 추가 @ManyToMany(cascade=CascadeType.ALL) cascade 참고 CascadeType의 종류에는 다음과 같은 것들이 있다. CascadeType.RESIST – 엔티티를 생성하고, 연관 엔티티를 추가하였을 때 persist() 를 수행하면 연관 엔티티도 함께 pers..

  • format_list_bulleted Programming/JPA
  • · 2017. 6. 15.
  • textsms
  • navigate_before
  • 1
  • navigate_next
반응형
공지사항
전체 카테고리
  • ALL (217)
    • 쿠베플로우 kubeflow (1)
    • React Native (1)
      • Expo (1)
    • Programming (187)
      • spring+jwt+react (4)
      • wordpress (3)
      • Vultr (1)
      • Flutter (3)
      • Vue-project (1)
      • Vue-tip (17)
      • AngularJS (12)
      • Bootstrap (2)
      • Book (1)
      • CentOS (5)
      • Code (0)
      • Css (13)
      • Docker (7)
      • Eclipse (1)
      • Freemarker (1)
      • Git (9)
      • Front-End (6)
      • Error (7)
      • Gulp.js (0)
      • Java (12)
      • Python (5)
      • Javascript (19)
      • JPA (5)
      • jQuery (2)
      • Mac (6)
      • MySql (4)
      • Springboot (21)
      • Springboot-blog (0)
      • Daily (1)
      • Springboot-tip (3)
      • Spring (1)
      • Thymeleaf (1)
      • Tomcat (1)
      • Typescript (3)
      • Tool (5)
      • Sql (1)
      • prisma (1)
      • react (1)
    • Life (14)
      • Review (0)
      • Tip (3)
      • 리뷰 (8)
      • 부동산 (2)
최근 글
인기 글
최근 댓글
태그
  • #GIT
  • #css
  • #sts
  • #error
  • #Vue
  • #JPA
  • #springboot
  • #javascript
  • #MySQL
  • #AngularJS
전체 방문자
오늘
어제
전체
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바