
어쩔 수 없는 상황이 아니라면 가급적 사용하지 않는 것이 좋음 사용 법은 단순하다. @Query(value = "select * from member where username = ?" , nativeQuery = true) Member findByNativeQuery(String username); @Query에 nativeQuery를 true로 주면 끝이다. 프로젝션과 함께 사용하기 package study.datajpa.repository; public interface MemberProjection { Long getId(); String getUsername(); String getTeamName(); } @Query(value="select m.member_id as id, m.username..
projections이란 쉽게 말해서 쿼리에 셀렉트 절에 들어갈 데이터(필드) 라고 보면된다고 한다. 엔티티 대신에 DTO를 편리하게 조회할 때 사용 전체 엔티티가 아니라 만약 회원 이름만 딱 조회하고 싶으면? 1. 인터페이스를 하나 만든다. 값을 얻고싶은 메소드만 만들어주기 package study.datajpa.repository; public interface UsernameOnly { String getUsername(); } 2. repository에는 반환형태를 인터페이스 네임으로 붙여준다 List findProjectionByUsername(@Param("username")String username); } 3.메소드를 사용해서 반환한다. @Test public void projections..
@Test public void queryByExample(){ Team teamA = new Team("teamA"); em.persist(teamA); Member m1 = new Member("m1", 0, teamA); Member m2 = new Member("m2", 0, teamA); em.persist(m1); em.persist(m2); em.flush(); em.clear(); //probe 생성 Member member = new Member("m1"); //username 검색 Team team = new Team("teamA"); member.setTeam(team); //연관관계까지 검색해줌 //ExampleMatcher 생성 , age 프로퍼티는 무시 ExampleMatcher..
술어(predicate) - 참 또는 거짓으로 평가 - AND OR 같은 연산자로 조합해서 다양한 검색조건을 쉽게 생성(컴포지트 패턴) - 예) 검색 조건 하나하나 - 스프링 데이터 JPA는 'org.springframework.data.jpa.domain.Specification' 클래스로 정의 package study.datajpa.repository; import jakarta.persistence.criteria.*; import org.springframework.data.jpa.domain.Specification; import study.datajpa.entity.Member; import study.datajpa.entity.Team; public class MemberSpec { publ..

data JPA 구현체는 SimpleDataJpa 객체이다. - 메소드를 확인하면 알겠지만, Tranjection이 걸려 있어서, 만약 트렌젝션을 서비스에서 걸지 않더라도 알아서 진행한다. (하지만 영속성턴텍스트를 이용해야하기 때문에 서비스에 걸어주는게 맞다) - JPA를 사용해도 여타 JDBC와 같은 예외가 나오도록 설정되어있다. /* * Copyright 2008-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a ..

@GetMapping("/members") public Page list(Pageable pageable){ Page findMembers = memberRepository.findAll(pageable); return findMembers; } 이렇게 사용하는 것 만으로 페이징이 가능하다. - GET 요청의 파라미터 값을 주는 것으로 페이징을 조절 가능하다. default는 20개로 되어있으며 변경이 가능하다. 글로벌 변경 spring: datasource: url: jdbc:h2:tcp://localhost/~/jpashop username: sa password: driver-class-name: org.h2.Driver jpa: hibernate: ddl-auto: create properties..
package study.datajpa.controller; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import study.datajpa.entity.Member; import study.datajpa.repository.MemberRepository; @RestController..

등록 수정에 대한 내용이 없으면 유지보수 등 나중에 확인할 때에 문제가 생길 수도 있다. 김영한개발자님은 모든 테이블에 등록, 수정 내용을 꼭 남긴다고 한다. 같은 데이터의 모양이므로 하나의 클래스로 진행한다. 실무에서도 자주 쓰는 기술이라 한다. 순수 JPA package study.datajpa.entity; import jakarta.persistence.Column; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; import java.time.LocalDateTime; @MappedSuperclass public class Jp..
- Total
- Today
- Yesterday
- rejectValue
- Java
- thymleaf
- reject
- React
- 인터셉터
- HTTP
- 컨트
- SpringBoot
- filter
- ArgumentResolver
- 향해99
- 예외처리
- 항해99
- 로그인
- Intercepter
- 향해플러스백엔드
- 향해플러스
- 백엔드 개발자 공부
- hypertexttransferprotocol
- 스프링공부
- exception
- JPA
- jpa api
- 백엔드 개발자 역량
- BindingResult
- 항해플러스
- 스프링부트
- 리터럴
- react실행
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |