본문 바로가기

JAVA/JPA

(5)
[Spring] Mybatis와 JpaRepository 인터페이스 하나의 repository로 관리하기 TestSample(entity)객체 와 같은 디렉토리에 TestSampleRepository 생성 extends JpaRepository, TestSampleRepositoryCustom(네이밍 꼭 맞춰야함) 추가 @Repository public interface TestSampleRepository extends JpaRepository, TestSampleRepositoryCustom { } TestSampleRepositoryCustom 인터페이스 생성, 사용할 메소드명 및 파라미터 지정 public interface TestSampleRepositoryCustom { TestSample test() { } } TestSampleRepositoryImpl 클래스 생성 후 implements Te..
[Spring] Querydsl 설정하기 사전 작업 : [Spring] JPA Sample 파일명 : build.gradle 최상단에 다음의 buildScript 추가 // queryDsl buildscript { ext{ querydslPluginVersion = '1.0.10' } repositories { maven { url "https//plugins.gradle.org/m2/"} } dependencies { classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:${querydslPluginVersion}") } } 이 후 각자 설정에 맞는 위치에 밑줄 친 내용 추가 configurations { developmentOnly runtimeClasspath { extend..
[Spring] JPA Sample 디렉토리 구조 java com/ controller/ help/ TestJpaSampleController service/ help/ TestJpaSampleService domain/ db/ bncadm/ testsample/ TestSample TestSampleRepository test com/ controller/ help/ TestJpaSamplceControllerTest DB에 테이블 만들기 CREATE TABLE test_sample ( id VARCHAR(20) NOT NULL, name VARCHAR(20) NOT NULL, age Integer, ins_tm TIMESTAMP DEFAULT NOW(), primary key(id) ) 객체 만들기 @Getter @Setter @NoA..
[Spring] 헷갈리는 용어 JPA, Hibernate, Spring data JPA 차이점 Spring을 공부하다보면 JPA를 만나게 된다. 보통 학습곡선이 높다는 이유로 또는 실제로 사용하기 어렵다는 이유로 이야기만 대충 듣고 넘어가는 편이 많을 것이라고 아주 지극히 개인적인 생각을 하고 있다. 나 또한 "JPA는 학습곡선이 높으니 나중에 시간이 많이 남으면 적용은 해보자" 라고 막연한 불안감에 시작도 하지 못하고 있었다. 물론 지금도 잘 사용하는 편은 아니지만 다른 이들이 나와 같은 고민으로 시간을 낭비하지 않길 바라며 기록을 남겨본다. JPA, Hibernate, Spring JPA 각각의 차이점은 무엇일까? JPA라고 불리는 것에 대해서 사람마다 지역마다 다른 이름으로 부르는 것이 아니였나? 이에 대한 궁금증을 해소하고자 한다. 가장 범용적으로 불리던 JPA란 과연 무엇인가? 우선은 J..
[Spring] Spring JPA 시작하기(기본 설정 값, JPA 객체 생성) 현재까지는 스프링 부트를 사용하면서 DB 관리를 위하여 마이바티스를 사용하고 있었다. 그러나 반복적인 코드 작성으로 인한 시간 소모가 생각보다 크다는 것을 알게 되었고 이를 소폭이라도 감소시키기 위하여 JPA를 사용하기로 하였다. 역시나 스프링이 지원해주는 스프링 JPA를 사용하여 빠른 개발을 해보자. 어플리케이션에 JPA 셋팅 의존성 관리 // 스프링MVC를 위한 Spring boot starter 패키지 implementation 'org.springframework.boot:spring-boot-starter-web' // 스프링JPA를 위한 패키지 implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jp..