Back End/Spring Data JPA
-
[Spring JPA] 쿼리메소드, JPQL, NativeQuery (@Query)Back End/Spring Data JPA 2021. 11. 1. 22:33
# JPA 자체 제공 쿼리메소드 FindAllByMyentity 와 같이 keyword 로 정의하는 쿼리메소드 허나, 조건이 길어지면 괴랄한 이름의 메소드들이 나온다. (FindEmailByEmailAndUserIdGreaterThan 같은...) https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repository-query-keywords Spring Data JPA - Reference Documentation Example 109. Using @Transactional at query methods @Transactional(readOnly = true) interface UserRepository extends JpaRepo..
-
[Spring JPA] Repository Query KeywordsBack End/Spring Data JPA 2021. 10. 27. 19:36
# Query subject keywords https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#appendix.query.method.subject Spring Data JPA - Reference Documentation Example 109. Using @Transactional at query methods @Transactional(readOnly = true) interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.ac..
-
[Spring JPA] DB transaction isolation(격리수준) 개념 및 사용방법Back End/Spring Data JPA 2021. 10. 27. 19:13
# DB 트랜잭션 격리수준 개념 https://developer-ping9.tistory.com/177 [DB] DB transaction isolation(격리수준) 개념 # 트랜잭션 격리수준 4 단계 1. READ_UNCOMMITED DB에 커밋되지 않은 데이터를 읽을 수 있다. Dirty Read 로 인해 데이터 정합성에 심각하게 문제를 야기하므로, 실제 서비스에서 거의 쓰이지 않는다. # Di developer-ping9.tistory.com # JPA에서 사용방법 두개의 Annotation 이 있는데, springframwork 의 Transactional 에만 isolation 옵션이 있으므로 1번째를 사용해야 한다. // @Transactional 은 클래스, 메소드 위에만 사용가능하다. /..
-
[Spring JPA] Spring Data JPA Annotation & JPA EventBack End/Spring Data JPA 2021. 10. 22. 22:17
# Entity level Annotation @Entity - class scope 해당객체가 JPA에서 관리하는 엔티티 객체임을 정의 @Id - field scope 해당멤버변수가 PK임을 선언 직접 할당 @GeneratedValue - field scope @Id 와 함께 사용하여 PK가 자동생성되도록 함 @GeneratedValue(strategy=Auto) JPA가 알아서 DB맞게 넣어줌 @GeneratedValue(strategy=TABLE) id를 테이블로 관리 (조회는 빠르나, 데이터수가많을수록 힘들겠지?) @GeneratedValue(strategy=IDENTITY) 테이블마다 해당 id 값을 auto-increment로 지정하여 지속적으로 값을 증가시켜줌 em.persist(sql in..
-
[Spring JPA] data.sql 동작방식 변경, hibernate_sequence not found 해결법Back End/Spring Data JPA 2021. 10. 19. 20:27
Spring 강의를 들으며 공부하시는 분들 중, 해당 강의가 Spring boot 2.5 이전버전 기준으로 진행되는 강의일 경우 call next value for hibernate_sequence; 를 data.sql 에 입력했다가 잘못된 syntax 어쩌구 'hibernate_sequence not found' 를 목격하게 될 것이다. 해당 에러문구를 읽어보면 분명 해당명령어를 찾지못해 발생하는 건데 dependencies 에 따로 hibernate를 추가해야되나 싶었지만, 검색해보니 hibernate는 spring-data-jpa 안에 이미 들어있었다. call next value for hibernate_sequence; 가 문제인가 싶어 지워도 오류가 뜰 것이다. ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ create..
-
[Spring JPA] JPA, Hibernate, Spring Data, ORM 의 개념Back End/Spring Data JPA 2021. 10. 19. 12:49
# ORM(Object Relational Mapping) Application의 객체(클래스)를 DB의 테이블로 Mapping 한다는 개념 클래스와 DB의 테이블은 기존부터 호환가능성을 염두해두고 만들어진 것이 아니기 때문에 불일치 발생이 당연 이러한 불일치를 해결하며 객체와 테이블의 관계를 바탕으로 SQL 문장을 자동으로 생성하여 객체로 DB를 조작하게 해주는 것이 ORM # JPA(Java Persistence API) JAVA진영의 표준 ORM 인터페이스, 구체 클래스는 거의 없음. # Hiberante JPA를 implements 해 구현한 class 라이브러리 DataNucleus, EclipseLink 등 JPA를 구현한 다른 라이브러리도 있다. # Spring Data JPA JPA를 한 ..