Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 알고리즘
- kotlin
- Android
- pointcut
- 백준
- Greedy
- JDBC
- 자바
- 김영한
- db
- http
- AOP
- 스프링 핵심 기능
- SpringBoot
- Thymeleaf
- 스프링
- 스프링 핵심 원리
- java
- JPQL
- jpa
- Exception
- transaction
- 그리디
- Spring Boot
- springdatajpa
- QueryDSL
- spring
- 인프런
- Servlet
- Proxy
Archives
- Today
- Total
개발자되기 프로젝트
세팅하기 본문
1. application.yml
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/datajpa
username: sa
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
format_sql: true
logging.level:
org.hibernate.SQL: debug
2. 엔티티를 만들자.
@Entity
@Getter @Setter
public class Member {
@Id @GeneratedValue
private Long id;
private String userName;
protected Member() {
}
public Member(String userName) {
this.userName = userName;
}
public void changeUserName(String userName){
this.userName = userName;
}
}
3. Repository를 만들자.
크..
public interface MemberRepository extends JpaRepository<Member, Long> {
}
4. 잘 돌아가는지 test
@SpringBootTest
@Transactional
@Rollback(value = false)
class MemberRepositoryTest {
@Autowired MemberRepository memberRepository;
@Test
public void testMember(){
Member member = new Member("memberA");
Member savedMember = memberRepository.save(member);
Optional<Member> byId = memberRepository.findById(savedMember.getId());
Member findMember = byId.get();
Assertions.assertThat(findMember.getId()).isEqualTo(savedMember.getId());
Assertions.assertThat(findMember.getUserName()).isEqualTo(savedMember.getUserName());
Assertions.assertThat(findMember).isEqualTo(member);
}
}
5. GitHub : initialcommit
'인프런 > [인프런] Spring Data JPA' 카테고리의 다른 글
JPA NamedQuery (0) | 2021.08.28 |
---|---|
쿼리 메서드 (0) | 2021.08.28 |
공통 인터페이스 설정, 적용, 분석 (0) | 2021.08.28 |
공통 인터페이스 기능 : 순수 jpa기반 repository (0) | 2021.08.28 |
예제 도메인 모델과 동작 확인하기. (0) | 2021.08.27 |
Comments