본문 바로가기

java3

Type Erasure와 ParameterizedTypeReference Generic으로 생성한 인스턴스에서 타입을 유추하는 방법과, Type erasure로 인한 문제점, 그리고 Generic에서 타입 추론을 해결하기 위한 ParameterizedTypeReference까지 알아보자. class GenericSample { T value; public GenericSample(T value) { this.value = value; } public T getValue() { return value; } } 위와 같이 Generic value 하나를 갖는 클래스를 선언한 뒤 인스턴스를 생성한다. 생성한 인스턴스를 reflection으로 타입을 가져와보면 결과는 다음과 같다. final GenericSample integerGeneric = new GenericSample(10.. 2021. 1. 2.
JPA로 batch insert 하는 방법 여러 entity를 table에 생성을 해야 하는 경우, 하나씩 n번 생성하는 것보다는 bulk로 묶어서 생성하는 편이 여러모로 좋다. JPA의 구현체에 .saveAll 로 Iteratable 을 인자로 받는 메소드가 있어서 아주 적은 노력으로 구현했지만, 실제 디버깅 레벨로 쿼리를 출력해보니 하나씩 처리하고 있었다. 인터페이스는 마치 INSERT INTO {TABLE} VALUES ([..., ...]) 꼴의 쿼리로 변환될 것처럼 보였는데, 하나씩 처리하고 있으니 그 원인을 찾아봤다. 역시 가장 먼저 이와 관련된 설정 값이 있다. spring.jpa.properties.hibernate.jdbc.batch_size=20 hibernate에게 batch 처리를 가능하도록 그 크기에 대한 설정 값을 0보다.. 2020. 2. 20.
gradle로 spring-boot 프로젝트 설정 gradle로 프로젝트를 생성하고 build.gradle을 아래와 같이 수정한다. buildscript { ext { springBootVersion = '2.2.1.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 repositories { mavenCe.. 2019. 11. 19.