묻고 답해요
164만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결그림으로 배우는 자바, 파트2: 객체지향!
안녕하세요. 생성자관련?하여 질문드립니다.
자식클래스가 부모클래스를 상속하는 경우에 부모클래스의 필드값을 쓰고싶으면 생성자를 통해 초기화를 보통 했었는데요. 갑자기 든 생각인데 자식클래스에서 부모클래스의 값을 바로 초기화 할 수 있는 방법은 없는걸까요? 부모클래스(동물), 자식클래스(조류)인 경우에 public class 동물{ String value; } 일때 자식클래스에서 동물의 참조변수를 만들어서 동물 클래스의 value에 접근하려해도 안되고, 당연하지만 '.'으로 접근도 불가능해서 public class 조류{ public 조류(){ value = "새"; } } 이런식으로 꼭 생성자를 통해서만 초기화가 가능한걸까요?
-
미해결[C#과 유니티로 만드는 MMORPG 게임 개발 시리즈] Part4: 게임 서버
OnAcceptCompeted 함수 질문드립니다..
_onAcceptHandler.Invoke(args.AcceptSocket); 부분에서 _onAcceptHandler에서 object가 null 값이 되면서 오류가 발생합니다. 이 오류가 왜 발생하는지 잘 모르겠습니다.
-
해결됨Vue.js 끝장내기 - 실무에 필요한 모든 것
질문있습니다!
클론을받고서 npm i 를했는데 이렇게뜨네요..npm audit fix 를하면 found숫자가 줄기는합니다 근데 다줄지는않아요
-
해결됨13가지 예제로 배우는 CSS Flex & Grid 핵심 기능
한꺼번에 잡는 단축키
1:20 에 나오는 한꺼번에 잡는 단축키가 무엇일까요..?
-
미해결Three.js로 시작하는 3D 인터랙티브 웹
혹시 gltfloader
수업 들은 예제들을 리액트 프로젝트에서 열어보려고 react-create-app 으로 프로젝트 생성한 다음 컴포넌트 만들고 canvas 태그 만든후 useRef로 접근하여 렌더러 생성해주었습니다. 그리고 gltfLoader 사용해서 만든 glb 파일 불러오려는데 GLTFLoader.js:185 SyntaxError: Unexpected token < in JSON at position 0 자꾸 이렇게 에러가 뜹니다 ㅠㅠ 어떤게 문제인가요..?
-
해결됨실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발
일대 다 & 다대일 관계 삭제 시
안녕하세요! 더운 여름인데 건강은 잘 챙기고 계신지요? 항상 고생 많으십니다! 예제의 Order - OrderItem - Item 관계에서 삭제 시에 궁금한 점이 있어서 고민하다가 남겨봅니다..! 현재 Order에서 OrderItem을 @OneToMany(cascadeType.ALL)로 가지고 있어, Order save & 삭제시에는 OrderItem이 cascade 되어 저장, 삭제가 되고 있습니다. 하지만 Item에는 OrderItem -> Item간 단방향 mapping만 걸려있습니다. 만약 Item이 삭제될 경우에는 FK 제약조건으로 예외가 발생하게 됩니다. 이를 위한 해결방안으로 아래 3가지를 고려해보았습니다. Item에도 OrderItem Collection을 두고, Cascade 또는 Orphanremoval을 통해 연관된 OrderItem을 삭제한다.-> 삭제 시에만 사용되므로 비효율적으로 생각됨. Item을 soft delete로 관리한다. OrderItem(repository)을 대상으로 삭제하려는 Item을 FK로 가진 내용을 모두 삭제한 후 마지막으로 Item을 제거한다. 여러 질문에서 남겨주신 Cascade 관련 답변을 읽어보았고, 해당 엔티티를 한쪽에서 life cycle을 확실히 관리할 경우에만 사용하라고 이해를 했습니다. 하지만 위의 1처럼 양쪽에서 관리를 할 경우에도 개발자가 확실하게 life cycle을 이해한다면 문제가 없을 것으로 보이는데, 잘못 생각하고 있는걸까요? 중간 테이블에 대한 추가 / 제거를 고려하기가 쉽지 않네요..! 고려한 방법에서 발생할 수 있는 문제가 어떤건지, 더 좋은 방법이 있는지 질문드립니다!
-
미해결[개정판] 딥러닝 컴퓨터 비전 완벽 가이드
mmdetection mask-rcnn 추론결과 title 이름 변경 관련
안녕하세요 강사님 mmdetection 관련해서 이론적으로나 실무적으로나 항상 많은 도움 받고있습니다. 강의 내용을 바탕으로 mmdetection code를 작성하던 도중 질문사항이 생겨서요 ㅎㅎ mmdetection Mask R-CNN 모델을 이용하여 추론결과 아래 사진과 같이 mask, bbox 두가지가 나타나는데 bbox위에 나타나는 title(coin) 대신 변수를 표시하고 싶습니다. class name, confidence score 가 아닌 ID, pixel number를 표시하고 싶습니다. 제 코드는 다음과 같습니다. img_name = path_dir + '/' + file_list[i] img_arr= cv2.imread(img_name, cv2.IMREAD_COLOR) img_arr_rgb = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB) # cv2.imshow('img',img) fig= plt.figure(figsize=(12, 12)) plt.imshow(img_arr_rgb) # inference_detector의 인자로 string(file경로), ndarray가 단일 또는 list형태로 입력 될 수 있음. results = inference_detector(model, img_arr) #추론결과 디렉토리에 저장 model.show_result(img_arr, results, score_thr=0.8, title= bbox_color=(0,0,255),thickness=0.5,font_size=7, out_file= f'{save_dir1}{file_list[i]}') 이 결과 추론되는 사진은 다음과 같습니다 아래는 mmdetection/mmdet/core/visualization/image.py에 있는 imshow_det_bboxes 함수입니다. 아래 함수가 시각화 해주는 함수여서 해당 함수를 수정하면 될 것 같은데 아무리 뜯어봐도 어디를 고쳐야할 지 도저히 감이 오질 않습니다 ...ㅠㅠ def imshow_det_bboxes(img, bboxes, labels, segms=None, class_names=None, score_thr=0, bbox_color='green', text_color='green', mask_color=None, thickness=2, font_size=13, win_name='', show=True, wait_time=0, out_file=None): """Draw bboxes and class labels (with scores) on an image. Args: img (str or ndarray): The image to be displayed. bboxes (ndarray): Bounding boxes (with scores), shaped (n, 4) or (n, 5). labels (ndarray): Labels of bboxes. segms (ndarray or None): Masks, shaped (n,h,w) or None class_names (list[str]): Names of each classes. score_thr (float): Minimum score of bboxes to be shown. Default: 0 bbox_color (str or tuple(int) or :obj:`Color`):Color of bbox lines. The tuple of color should be in BGR order. Default: 'green' text_color (str or tuple(int) or :obj:`Color`):Color of texts. The tuple of color should be in BGR order. Default: 'green' mask_color (str or tuple(int) or :obj:`Color`, optional): Color of masks. The tuple of color should be in BGR order. Default: None thickness (int): Thickness of lines. Default: 2 font_size (int): Font size of texts. Default: 13 show (bool): Whether to show the image. Default: True win_name (str): The window name. Default: '' wait_time (float): Value of waitKey param. Default: 0. out_file (str, optional): The filename to write the image. Default: None Returns: ndarray: The image with bboxes drawn on it. """ assert bboxes.ndim == 2, \ f' bboxes ndim should be 2, but its ndim is {bboxes.ndim}.' assert labels.ndim == 1, \ f' labels ndim should be 1, but its ndim is {labels.ndim}.' assert bboxes.shape[0] == labels.shape[0], \ 'bboxes.shape[0] and labels.shape[0] should have the same length.' assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5, \ f' bboxes.shape[1] should be 4 or 5, but its {bboxes.shape[1]}.' img = mmcv.imread(img).astype(np.uint8) if score_thr > 0: assert bboxes.shape[1] == 5 scores = bboxes[:, -1] inds = scores > score_thr bboxes = bboxes[inds, :] labels = labels[inds] if segms is not None: segms = segms[inds, ...] mask_colors = [] if labels.shape[0] > 0: if mask_color is None: # Get random state before set seed, and restore random state later. # Prevent loss of randomness. # See: https://github.com/open-mmlab/mmdetection/issues/5844 state = np.random.get_state() # random color np.random.seed(42) mask_colors = [ np.random.randint(0, 256, (1, 3), dtype=np.uint8) for _ in range(max(labels) + 1) ] np.random.set_state(state) else: # specify color mask_colors = [ np.array(mmcv.color_val(mask_color)[::-1], dtype=np.uint8) ] * ( max(labels) + 1) bbox_color = color_val_matplotlib(bbox_color) text_color = color_val_matplotlib(text_color) img = mmcv.bgr2rgb(img) width, height = img.shape[1], img.shape[0] img = np.ascontiguousarray(img) fig = plt.figure(win_name, frameon=False) plt.title(win_name) canvas = fig.canvas dpi = fig.get_dpi() # add a small EPS to avoid precision lost due to matplotlib's truncation # (https://github.com/matplotlib/matplotlib/issues/15363) fig.set_size_inches((width + EPS) / dpi, (height + EPS) / dpi) # remove white edges by set subplot margin plt.subplots_adjust(left=0, right=1, bottom=0, top=1) ax = plt.gca() ax.axis('off') polygons = [] color = [] for i, (bbox, label) in enumerate(zip(bboxes, labels)): bbox_int = bbox.astype(np.int32) poly = [[bbox_int[0], bbox_int[1]], [bbox_int[0], bbox_int[3]], [bbox_int[2], bbox_int[3]], [bbox_int[2], bbox_int[1]]] np_poly = np.array(poly).reshape((4, 2)) polygons.append(Polygon(np_poly)) color.append(bbox_color) label_text = class_names[ label] if class_names is not None else f'class {label}' if len(bbox) > 4: label_text += f'|{bbox[-1]:.02f}' ax.text( bbox_int[0], bbox_int[1], f'{label_text}', bbox={ 'facecolor': 'black', 'alpha': 0.8, 'pad': 0.7, 'edgecolor': 'none' }, color=text_color, fontsize=font_size, verticalalignment='top', horizontalalignment='left') if segms is not None: color_mask = mask_colors[labels[i]] mask = segms[i].astype(bool) img[mask] = img[mask] * 0.5 + color_mask * 0.5 plt.imshow(img) p = PatchCollection( polygons, facecolor='none', edgecolors=color, linewidths=thickness) ax.add_collection(p) stream, _ = canvas.print_to_buffer() buffer = np.frombuffer(stream, dtype='uint8') img_rgba = buffer.reshape(height, width, 4) rgb, alpha = np.split(img_rgba, [3], axis=2) img = rgb.astype('uint8') img = mmcv.rgb2bgr(img) if show: # We do not use cv2 for display because in some cases, opencv will # conflict with Qt, it will output a warning: Current thread # is not the object's thread. You can refer to # https://github.com/opencv/opencv-python/issues/46 for details if wait_time == 0: plt.show() else: plt.show(block=False) plt.pause(wait_time) if out_file is not None: mmcv.imwrite(img, out_file) plt.close() return img 감사합니다
-
미해결파이썬/장고 웹서비스 개발 완벽 가이드 with 리액트
uuid 에러 관련입니다!
어디서 에러가 발생한 것인지는 알겠으나 왜 에러가 발생한건지, 또 해결 방법은 무엇인지가 너무 궁금합니다!
-
미해결모든 개발자를 위한 HTTP 웹 기본 지식
돌아왔습니다..
개발에 대하여 더 깊이 학습하고자 김영한님 스프링MVC강의를 듣는 도중에 HTTP에 대한 지식이 너무 부족하다 느껴서 듣던 스프링mvc 강의를 멈추고 이번 강의부터 시작하여 HTTP에 대한 이해를 더 높이고 스프링MVC강의를 다시 들으려 합니다 ! 화이팅
-
미해결스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술
test 오류 질문
test 부분 실습하면서 코드를 그대로 작성했는데 계속 같은 오류가 뜹니다...! 코드는 똑같이 적어서도 했고 복사 후 붙여넣기도 해 봤는데 안 돼서 문의 드립니다!! 아마 get 부분에서 계속 오류가 나는 것 같습니다
-
미해결비전공 기획자 및 관리자를 위한 IT 필수 지식
강의 자료 요청
강사님, 안녕하세요. 강의자료 요청 드립니다. 아래 메일로 공유 부탁드립니다! goonee265@naver.com
-
해결됨Slack 클론 코딩[백엔드 with NestJS + TypeORM]
쿼리빌더 사용과 조인과 셀렉트에 관련된 질문입니다.
안녕하세요 조현영님. 이번에는 쿼리빌더로 원하는 데이터를 얻기 위해 조인과 셀렉트 과정에서 오류가 발생하여 질문드립니다. 일단 질문을 드리기 전에 제 상황에 대한 사전지식이 필요하기 때문에 코드를 같이 보여드리겠습니다. @Entity("users") export class UserEntity extends CommonEntity { @OneToOne(() => UserProfileEntity, (common) => common.id) @JoinColumn({ name: "commonId", referencedColumnName: "id" }) profile: UserProfileEntity; @OneToOne(() => UserAuthEntity, (auth) => auth.id) @JoinColumn({ name: "authId", referencedColumnName: "id" }) auth: UserAuthEntity; @OneToOne(() => UserActivityEntity, (activity) => activity.id) @JoinColumn({ name: "activityId", referencedColumnName: "id" }) activity: UserActivityEntity; } 사용자에 관련된 엔티티입니다. 사용자와 관련된 컬럼들은 세부적으로 엔티티를 나눈 다음 그 엔티티안에 정의 해두었습니다. 사용자 엔티티에는 프로필, 인증, 활동 엔티티의 아이디만 존재합니다. 아래에는 사용자 엔티티에게 상속을 해주는 CommonEntity입니다. export abstract class CommonEntity { @IsUUID() @PrimaryGeneratedColumn("uuid") id: string; @CreateDateColumn({ type: "timestamp" }) createdAt: Date; @UpdateDateColumn({ type: "timestamp" }) updatedAt: Date; @DeleteDateColumn({ type: "timestamp" }) deletedAt: Date | null; } 아래에는 각각 프로필, 인증, 활동 엔티티의 대한 코드입니다. @Entity("users profile") export class UserProfileEntity { @PrimaryGeneratedColumn("uuid") id: string; @IsString() @IsNotEmpty() @Column({ type: "varchar", length: 20, nullable: false }) realname: string; @IsDateString() @IsNotEmpty() @Column({ type: "date", nullable: false }) birth: Date; @IsEnum(["male", "female"]) @IsNotEmpty() @Column({ type: "enum", enum: ["male", "female"] }) gender: "male" | "female"; @IsMobilePhone() @IsNotEmpty() @Column({ type: "varchar", length: 15, unique: true, nullable: false }) phonenumber: string; @OneToOne(() => UserEntity) user: UserEntity; } @Entity("users auth") export class UserAuthEntity { @PrimaryGeneratedColumn("uuid") id: string; @IsString() @IsNotEmpty() @Column({ type: "varchar", length: 20, unique: true, nullable: false }) nickname: string; @IsEmail() @IsNotEmpty() @Column({ type: "varchar", length: 60, unique: true, nullable: false }) email: string; @IsString() @IsNotEmpty() @Matches(/^[A-Za-z\d!@#$%^&*()]{8,30}$/) @Column({ type: "varchar", nullable: false }) password: string; @Column({ type: "enum", enum: ["general", "special", "admin"], default: "general", }) userType: "general" | "special" | "admin"; @OneToOne(() => UserEntity) user: UserEntity; @OneToMany(() => ImagesEntity, (join) => join.uploader) image: ImagesEntity[]; } @Entity("users activity") export class UserActivityEntity { @PrimaryGeneratedColumn("uuid") id: string; @Column({ type: "smallint", default: 0 }) bonusPoint: number; @Column({ type: "smallint", default: 0 }) purchaseCount: number; @Column({ type: "smallint", default: 0 }) productInquiryCount: number; @Column({ type: "smallint", default: 0 }) productReviewCount: number; @OneToOne(() => UserEntity) user: UserEntity; @OneToMany(() => ReviewEntity, (review) => review.reviewer) review: ReviewEntity; } 이런식으로 한 사용자 엔티티에는 프로필, 인증, 활등 에 대한 엔티티와 1:1 관계를 설정 해 두었습니다. 그리고 이제 특정 사용자에 대한 정보를 가져올 때 사용되는 메서드입니다. async findUserWithId(userId: string): Promise<UserEntity> { try { return await this.userRepository .createQueryBuilder("user") .innerJoinAndSelect("user.profile", "profile") .innerJoinAndSelect("user.auth", "auth") .innerJoinAndSelect("user.activity", "activity") .where("user.id = :id", { id: userId }) .getOneOrFail(); } catch (err) { throw new UnauthorizedException("해당 사용자아이디는 존재하지 않습니다."); } } userId 매개변수는 CommenEntity에서 상속된 id컬럼을 사용합니다. 즉 사용자 엔티티 id라고 보시면 됩니다. userRepository또한 아래처럼 사용자 엔티티의 리파지토리입니다. @InjectRepository(UserEntity) private readonly userRepository: Repository<UserEntity> 이제 본격적으로 문제에 관련된 질문을 드리자면 innerJoinAndSelect를 사용할 시 관계가 맺어진 엔티티들의 정보들을 모두 가져오게 되어서 노출이 되어서는 안될 비밀번호등 까지 보여지게 됩니다. 그래서 저는 innerJoinAndSelect대신 innerJoin으로 관계가 맺어진 엔티티들을 조인하고 select메서드로 원하는 컬럼만 선택하려했습니다. async findUserWithId(userId: string): Promise<UserEntity> { try { return await this.userRepository .createQueryBuilder("user") .select(this.select.UserInformationReturnProperty) .innerJoin("user.profile", "profile") .inneroin("user.auth", "auth") .innerJoin("user.activity", "activity") .where("user.id = :id", { id: userId }) .getOneOrFail(); } catch (err) { throw new UnauthorizedException("해당 사용자아이디는 존재하지 않습니다."); } } select안에 인수는 아래와 같습니다. UserInformationReturnProperty: [ "profile.realname", "auth.nickname", "profile.birth", "profile.gender", "auth.email", "profile.phonenumber", "auth.userType", "activity.purchaseCount", "activity.bonusPoint", "activity.productInquiryCount", "activity.productReviewCount", ] 이렇게 보여줘도 상관없을 만한 정보들로 구성하였습니다. 문제는 이렇게 하고 쿼리를 돌렸을 때 'EntityNotFoundError: Could not find any entity of type "UserEntity" matching: [object Object]'이런 오류가 납니다. 해석해보면 '일치하는 "UserEntity" 유형의 엔터티를 찾을 수 없음' 이런 뜻인거 같은데 분명히 리파지토리도 UserEntity이고 select 대신 innerJoinAndSelect를 하면 정상적으로 불러와 지는데 어떤 부분이 잘못된건지 모르겠어서 질문드립니다.
-
미해결파이썬/장고 웹서비스 개발 완벽 가이드 with 리액트
col-sm-12 태그에서 post_card 와 timeline_sidebar 가 가로로 정렬이 되지 않습니다
안녕하십니까 :) 유익한 수업 잘 듣고 있습니다! django templates 관련해서 index.html 태그와 timeline_sidebar.html 에서 코드가 동일한데 좌 우가 아닌 위 아래로 배치가 되고 있어요. (하단의 그림 1) 1. 검사와 html 태그와의 차이점(이상하다고 느낀 점) index.html 에서는 row 태그 안에 col-sm-8 과 col-sm-4 태그를 넣어서 배치했는데, 실제 웹에서 보면 col-sm-4 코드가 바깥으로 나온 것으로 보여집니다. include 를 해서 그런것인지, 그리드를 잘못 활용한 것인지 이유와 해결책이 궁금합니다! (그림 1)
-
미해결스프링 핵심 원리 - 고급편
추상클래스의 메서드를 포인트컷으로 잡을 수 없나요?
안녕하세요. AOP 포인트컷 관련 테스트를하다가 제가 잘 모르는 부분이 있어서 질문을 드립니다. 인터페이스에서 구체클래스의 내부메서드를 포인트컷으로 잡지 못하는것은 이해가 잘되는데요. 구체클래스(자식클래스)에서 부모클래스를 잡을 수 있을것이라고 생각했는데테스트해보니, 제 의도와 다른결과가 나오더라고요. 프록시는 프록시 클래스의 메서드(직접 정의했거나 Override)만 대상이 되나요? 어떤부분,키워드로 이해를 위한, 부족한 지식을 보완할 수 수 있을까요..?강의에 언급되었는데 제가 놓쳤다면, 그 부분을 알려주시면 다시 보도록 하겠습니다. 감사합니다. --- 샘플코드: https://github.com/seolys/spring-aop-pointcut-oop- 테스트코드로 작성하였습니다: 테스트코드 경로
-
미해결파이썬 알고리즘 문제풀이 입문(코딩테스트 대비)
이렇게 풀어도 될까요??
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 import sys sys.stdin=open("pythonalgorithm/섹션 2/9. 주사위 게임/in1.txt", "rt") n=int(input()) tot=[] for _ in range(n): tmp=list(map(int,input().split())) tmp.sort() a, b, c = tmp if a==b==c: tot.append(10000+a*1000) elif a==b or a==c: tot.append(1000+a*100) elif b==c: tot.append(1000+b*100) else: tot.append(c*100) print(max(tot)) 운영 관련 문의는 1:1 문의하기를 이용해주세요.
-
미해결[리뉴얼] Node.js 교과서 - 기본부터 프로젝트 실습까지
노드 버전에 따른 패키지 버전 관련하여 궁금합니다.
선생님 안녕하세요, 좋은 강의 잘 듣고있습니다. 다름이 아니라 노드 버전에 따른 패키지 버전 관련하여 궁금합니다. 예를 들어 예전 노드 버전에서 최신 express 패키지를 사용하면 문제가 있을 수 있는 것처럼 해당 노드 버전에 맞는 패키지 버전을 알 수 있는 npm 명령어 또는 사이트가 있는지 궁금합니다. 구글링을 해봤는데, 잘 안나오네요... ㅠㅠ 혹시 알고 계시다면 답변 부탁드리겠습니다. 강의랑 책 모두 잘 보고있습니다. 감사합니다 :)
-
미해결스파크 머신러닝 완벽 가이드 - Part 1
databricks 클러스터 생성하는 데 오류가 생깁니다
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. 2주가 지나서 구글 계정 하나를 다시 생성해서 회원 가입 후 클러스터를 생성해보려 하는 데 backend service unavailable이라는 에러가 뜨면서 생성이 안됩니다. 왜 이러는 걸까요?
-
미해결실전! 스프링 데이터 JPA
컬렉션 페치조인 batch size 활용 후 두개이상의 depth의 toOne 관계 lazy loading 시 join 이나 한방쿼리 활용방법 질문
안녕하세요! 개인 프로젝트 중 만난 상황에 대해 질문이 있습니다! 컬렉션 페치조인, 페이징 처리시, batch size 를 활용하여 최적화를 진행 중입니다. 위와 같은 erd 에서 아티클을 페이징 조회 하면서 프로필, 태그 목록 까지 조회하고 싶습니다. 이때 아티클당 작성자의 프로필은 toOne 관계 이기 때문에 fetch join을 활용 하여 진행할 수 있었습니다. 이후에 프록시로 조회된 아티클 태그를 batch Size 를 이용해 n+1 문제 없이 조회하고 아티클 태그 에서는 태그를 조회해서 아티클->아티클태그->태그의 연관을 땡겨 올 수 있습니다. 결국 총 3회의 쿼리가 발생하는데 아티클 태그, 태그를 조회하는 추가 쿼리를 join 이나 where 절을 사용해 한방 쿼리로 묶을 수 있는 방법이 있는지 궁금합니다. @Override public List<ArticleJpaEntity> searchArticle(long offset, long limit) { //쿼리 1 List<ArticleJpaEntity> articles = query .selectFrom(articleJpaEntity) .distinct() .join(articleJpaEntity.authorProfile, profileJpaEntity).fetchJoin() .offset(offset) .limit(limit) .fetch(); //아티클 -> 아티클 태그 -> 태그의 lazy loading : 쿼리 2, 쿼리 3 /* ArticlJpaEntity 의 메서드 public List<String> getTagList() { //쿼리 2: 아티클 -> 아티클 태그 레이지 로딩 발생 return articleTags.stream() //쿼리 3 : 아티클 태그 -> 태그의 레이지 로딩 발생 .map(ArticleTagJpaEntity::getTagName).collect(toList()); } */ //조회된 아티클을 돌며 수동 레이지 로딩 - batch size 로 n+1 방지 for (ArticleJpaEntity article : articles) { article.getTagList(); } return articles; } querydsl 을 활용하였고 활용한 코드는 위와 같습니다. 발생한 쿼리를 요약하면 아래와 같습니다. 쿼리 1 select distinct a.*, p.* from article a inner join profile p on a.author_profile_id = p.id limit 20 쿼리 2 select at.* from article_tag at where at.article_id in (7, 8, 9) 쿼리 3 select t.* from tag t where t.id in (16, 17, 18) 참고로 전체 데이터는 아래와 같습니다. insert into profile (bio, image, user_id, username, id) values ('user1bio', 'user1image', 1, 'user1', 4); insert into profile (bio, image, user_id, username, id) values ('user2bio', 'user2image', 2, 'user2', 5); insert into profile (bio, image, user_id, username, id) values ('user3bio', 'user3image', 3, 'user3', 6); insert into article (author_profile_id, body, created_at, description, slug, title, updated_at, id) values (4, 'article7body', '2022-07-11 22:42:43', 'article7desc', 'article7slug', 'article7title', NULL, 7); insert into article (author_profile_id, body, created_at, description, slug, title, updated_at, id) values (5, 'article8body', '2022-07-11 22:42:43', 'article8desc', 'article8slug', 'article8title', NULL, 8); insert into article (author_profile_id, body, created_at, description, slug, title, updated_at, id) values (6, 'article9body', '2022-07-11 22:42:43', 'article9desc', 'article9slug', 'article9title', NULL, 9); -- 태그 16, 17, 18 insert into tag (name, id) values ('tag16', 16); insert into tag (name, id) values ('tag17', 17); insert into tag (name, id) values ('tag18', 18); -- 아티클 7 -> 아티클 태그 19 -> 태그 16 - tag16 -- 아티클 8 -> 아티클 태그 20 -> 태그 16 - tag16 -- 아티클 8 -> 아티클 태그 21 -> 태그 17 - tag17 -- 아티클 9 -> 아티클 태그 22 -> 태그 16 - tag16 -- 아티클 9 -> 아티클 태그 23 -> 태그 17 - tag17 -- 아티클 9 -> 아티클 태그 24 -> 태그 18 - tag18 insert into article_tag (article_id, tag_id, id) values (7, 16, 19); insert into article_tag (article_id, tag_id, id) values (8, 16, 20); insert into article_tag (article_id, tag_id, id) values (8, 17, 21); insert into article_tag (article_id, tag_id, id) values (9, 16, 22); insert into article_tag (article_id, tag_id, id) values (9, 17, 23); insert into article_tag (article_id, tag_id, id) values (9, 18, 24); === 요약 - 쿼리 2와 쿼리 3을 한방 처리 할 수 있나요??
-
미해결[엔트리] 코딩능력마스터 2급 자격증 강의
기출문제
기출문제는 어디서 다운받나요?
-
미해결Vue3 완벽 마스터: 기초부터 실전까지 - "실전편"
unref 질문이요
unref(params) 로 파라메터를 넘기는데 애초에 List에서 params.value를 넘겨도 동작에는 문제가 안생기는데요 unref 를 사용하는 목적이 궁급합니다.