반응형

2020/11/05 4

JPA 테스트 코드로 알아보자!

JPA 설정 및 테스트 코드 작성은 이전글에 작성하였습니다. 이번글에서 다루는 소스코드는 github에 있습니다. JPA 저장 후 조회 @Test void entity저장후조회() { //given final Long id = 1L; final String storeName = "스토어1"; final String storeAddress = "주소1"; Store store = Store.builder() .id(id) .name(storeName) .address(storeAddress) .build(); storeRepository.save(store); //when Store resultStore = storeRepository.findByName(storeName); //then Assertion..

Develop/spring-data 2020.11.05

Spring Data JPA 시작 그리고 예제

작성된 모든 소스는 github에 있습니다. 이번글에서는 JPA 설정부터 테스트코드(Junit5) 까지 작성하였습니다. 다음글에서 JPA 테스트 코드 기준으로 작동 원리에 대해서 정리하겠습니다. 프로젝트 생성 gradle dependencies를 제외한 설정은 default값 그대로입니다. application.yaml spring: profiles: active: local --- #local spring: profiles: local datasource: url: jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC&characterEncoding=utf8 username: root password: vnfmsqka0727! drive..

Develop/spring-data 2020.11.05

JPA Cannot resolve table, JPA Cannot resolve column

JPA Entity 작성 중 Intellij에서 에러 밑줄이 쳐진다. intellij에서 사용하는 database와 연동하여 작성한 컬럼이 존재하는지 체크하는 과정 중 에러가 발생하는 것이다. 해결 방안 인텔리제이에서 datasource 설정되어있는지 체크 인텔리제이 DataSource 할당되어있는지 체크 View > Tool windows > Persistence 클릭 나타나는 항목을 마우스 우클릭하여 Assign Data Sources 클릭 Data Source 할당

TroubleShooting 2020.11.05

Spring Data JPA란?

JPA란 무엇일까? Java Persistence API 인터페이스(Repository) 모음 자바 ORM 기술 표준 ORM이란? Object-relational mapping으로 객체 관계 매핑이다. 객체는 객체대로, 관계형 데이터베이스는 데이터베이스대로 설계하고 ORM이 중간에서 매핑한다. 작동 원리 어플리케이션에서 JPA를 사용하면 JPA 내부에서 JDBC API를 통해 SQL을 호출하고 DB와 통신한다. 장점 xml에 작성하는 query보다 간편하다. 테이블 DDL 수정 이력을 관리할 필요없다. Database의 table은 JPA의 Entity이다. table을 수정한다면 Entity를 수정하여 배포하기 때문에 history에 남게 된다. 유지보수에 용이하다. 테이블에 직접 접근하지 않고 Ent..

Develop/spring-data 2020.11.05
728x90
반응형