Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210624] JPQL @Modifying, countQuery(), 캐시(Cache), Queue 대신 LinkedList로 선언 #157

Open
JuHyun419 opened this issue Jun 24, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Jun 24, 2021

JPQL @Modifying

https://www.baeldung.com/spring-data-jpa-modifying-annotation

  • JPQL(Java Persistence Query Language) ==> RDB의 엔티티에 대한 쿼리를 만드는데 사용
  • @Modifying => JPQL에서 update, delete를 실행하기 위해 필요한 어노테이션
  • @Modifying 어노테이션 없이 테스트 할 때
    @Query("delete from Reply r where r.board.bno = :bno")
    void deleteByBno(@Param("bno") Long bno);

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.QueryExecutionRequestException: 
Not supported for DML operations [delete from org.zerock.board.entity.Reply r where r.board.bno = :bno]; 
nested exception is java.lang.IllegalStateException: 
org.hibernate.hql.internal.QueryExecutionRequestException: 
Not supported for DML operations [delete from org.zerock.board.entity.Reply r where r.board.bno = :bno]

image

image


    // Board 삭제 시 Reply 삭제
    @Modifying
    @Query("delete from Reply r where r.board.bno = :bno")
    void deleteByBno(@Param("bno") Long bno);

image



JQPL @query countQuery()

  • 페이징 처리에서 쿼리 전체 갯수
	/**
	 * Defines a special count query that shall be used for pagination queries to lookup the total number of elements for
	 * a page. If none is configured we will derive the count query from the original query or {@link #countProjection()} query if any.
	 */
	String countQuery() default "";

    @Query(value = "select b, w, count(r) " +
            "from Board b " +
            "left join b.member w " +
            "left join Reply r on r.board = b " +
            "GROUP BY b ",
            countQuery = "select count(b) from Board b")
    Page<Object[]> getBoardWithReplyCount(Pageable pageable);



캐시(Cache)

  • 캐시 히트(Cache hit): CPU가 참조하고자 하는 메모리가 캐시에 존재하고 있는 경우
  • 캐시 미스(Cache miss): CPU가 참조하고자 하는 메모리가 캐시에 존재하지 않는 경우



Queue 대신 LinkedList를 선언

  • LinkedList에는 구현 메소드가 좀 더 많음
  • addFirst, addLast, pollFirst, pollLast 등등
  • 첫번째, 마지막번째 element에 대한 제어가 더 쉬움
// x
Queue<Integer> queue = new LinkedList<>();
queue.addFirst(city); // 존재하지 않음

// o
LinkedList<Integer> queue = new LinkedList<>();
queue.addFirst(city);
@JuHyun419 JuHyun419 changed the title [20210624] JPQL @Modifying [20210624] JPQL @Modifying, countQuery() Jun 24, 2021
@JuHyun419 JuHyun419 changed the title [20210624] JPQL @Modifying, countQuery() [20210624] JPQL @Modifying, countQuery(), 캐시(Cache) Jun 24, 2021
@JuHyun419 JuHyun419 changed the title [20210624] JPQL @Modifying, countQuery(), 캐시(Cache) [20210624] JPQL @Modifying, countQuery(), 캐시(Cache), Queue 대신 LinkedList로 선언 Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant