Spring

JPQL(Java Persistence Query Language) : Entity 객체를 조회하는 쿼리 QueryDSL : 쿼리 메소드 : 쿼리메소드의 경우 조건이 많아지게 되면 메소드의 이름이 길어지는 단점이 있다. public interface BookRepository extends JpaRepository { List findByCategoryIsNullAndNameEqualsAndCreatedAtGreaterThanEqualAndUpdatedAtGreaterThanEqual(String name, LocalDateTime createdAt, LocalDateTime updatedAt); } !!! @Query 어노테이션을 사용하여 메소드 명을 줄이고 가독성을 높인다. @Query 어노테이션 사..
영속성 전이 : 하나의 객체에서 다음 객체에 영속성을 흐려 보내는 것 Cascade의 경우, 연관관계가 있는 엔티티에(@OneToMany, @OneToOne...) 있는 경우에 CascadeType에 사용 가능. CascadeType 클래스 (Enum 타입) ALL : 모든 엔티티에 영속성 전이. PERSIST : 엔티티 저장시 영속성 전이 MERGE : 엔티티 업데이트 시 영속성 전이 REMOVE : 엔티티 제거 작업 시 영속성 전이 REFRESH : 엔티티의 영속성을 재로딩. DETACH : 영속성을 관리하지 않고 영속성으로부터 분리하는 속성. 해당 영역으로 전이가 일어날 때 릴레이션 엔티티에도 함께 전이를 일이킬지에 대한 속성 값 예제 1. CascadeType.PERSIST CascadeType...
Ex) failed to lazily initialize a collection of role: com.test.jpa.jpaProj.domain.Publisher.books, could not initialize proxy - no Session org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.jpa.jpaProj.domain.Publisher.books, could not initialize proxy - no Session at app//org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyI..
트랜잭션 Transaction? : 트랜잭션이란 데이터베이스의 상태를 변화시키기 위해 수행하는 작업의 단위, 또는 한꺼번에 모두 수행되어야할 일련의 연산을 뜻함 원자성...일관성...독립성...영속성....(ACID) Spring과 Java에서의 트랜잭션 Spring의 @Transactional : Transactional의 경우 class위와 method위에 어노테이션을 붙여줄 수 있다. class의 경우 내부에 있는 각각의 method를 트랜잭션화 한다는 것으로 method에 추가로 붙이면 method에 붙은 걸 우선 적용후 class 트랜잭션이 적용된다. 예제 1. @Transactional(rollbackFor = Exception.class) 사용 @Transactional(rollbackFor..
1. 영속성 컨텍스트 Persistence Context : 데이터를 영속화하는데 사용하는 컨테이너, JPA 컨테이너 안에서 돌아가는 Entity를 관리하는 컨텍스트 주체가 되는 클래스 EntityManager 를 사용 -> Spring Boot JPA dependency를 통해 별도의 Persistence 파일 사용없이 Persistence 설정들을 처리해줌 EntityManager : 영속성 컨텍스트 내에서 Entity들을 관리, JpaSimpleRepository에서 직접적으로 EntityManager를 사용하지 않도록 한번더 감싸준 것 @SpringBootTest public class EntityManagerTest { @Autowired private EntityManager entityMan..
Console warning: @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final. private List userHistories = new ArrayList(); ^ 1 warning User.java @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name="user_id", insertable = false, updatable =..
에러 배경 : Controller 테스트 코드 작성 중 다음과 같은 에러를 만남. Controller @RestController public class HelloController { @GetMapping("/helloStart") public String helloStart(){ return "hello spring"; } } Test @WebMvcTest class HelloControllerTest { @Autowired private MockMvc mockMvc; @Test void helloStart() throws Exception{ mockMvc.perform(MockMvcRequestBuilders.get("/helloStart")) .andDo(print()) .andExpect(sta..
1. Swagger 적용 1) Swagger란? : 개발한 REST API를 편리하게 문서화 해주고, 이를 통해서 관리 및 제 3의 사용자가 편리하게 API를 호출해보고 테스트 할 수 있는 프로젝트이다 2) Spring Boot에서는 gradle dependencies에 추가하여 사용 /* build.gradle */ dependencies { ...//https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' } !주의 Spring 버전이 3.0이상인 경우 에러 발생 2.x.x로 낮..
defxyj
'Spring' 카테고리의 글 목록 (3 Page)