개발/Spring(6)
-
간단한 푸시 서비스 각 부분별 스레드 설정에 따른 결과
푸시 서비스가 아래와 같이 이루어져 있다고 하자.SQS로부터 메시지를 받는 SqsListener,비즈니스 로직을 처리하는 FirebaseService,FCM과 직접적으로 통신하는 Firebase SDK,Sqs의 기본 TaskExecutor우선 Sqs의 기본 TaskExecutor는 다음과 같이 정의된다.// AbstractPipelineMessageListenerContainer.classprotected TaskExecutor createTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); int poolSize = getContainerOptions().getMaxConcurrentMessages() * thi..
2024.12.12 -
OSIV(open session in view)
OSIV란?JPA나 Hibernate 같은 ORM을 사용할 때, 영속성 컨텍스트(Session)를 뷰 렌더링 단계까지 열어두는 패턴. 이를 통해 뷰를 렌더링할 때도 데이터베이스에 접근할 수 있게 됨.Hibernate에서는 세션(Session)이라고 부르는 것을 JPA에서는 영속성 컨텍스트라고 부른다. 따라서 해석을 해보자면 영속성 컨텍스트를 view단까지 열어둘 것인지를 설정하는 것이라고 생각하면 된다. 트랜잭션이 시작될 때 영속성 컨텍스트가 데이터베이스 커넥션을 가져오게 되는데OSIV가 true일 경우OSIV가 true이면 트랜잭션이 끝나도 커넥션을 반환하지 않고 유저에게 response가 응답된 후, 또는 html에 렌더링한 후에 데이터베이스 커넥션을 반환하고 영속성 컨텍스트도 그 때 사라진다. 따라..
2024.09.22 -
Hibernate 5와 6에서 fetch join, @BatchSize 그리고 페이징 처리
hibernate 6 버전에서는 아래와 같이 fetch join을 할 경우 자동으로 중복된 데이터(Nationality의 id값이 같은 경우)는 제거해준다고 한다. 참고자료(https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#hql-distinct)@Query("select n from Nationality n join fetch n.players p left join fetch p.club")List findAllByFetchJoin();하지만 그 미만의 버전에서는 이런 기능이 없었기 때문에 distinct를 붙여줘야 한다.@Query("select distinct n from Nation..
2024.09.20 -
OneToMany, ManyToOne 테스트
@NoArgsConstructor@AllArgsConstructor@Getter@Entitypublic class Nationality { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(unique = true) private String name; @OneToMany private List players; @Enumerated(EnumType.STRING) private Continent continent;}@Getter@NoArgsConstructor@AllArgsConstructor@Entitypublic class Player { @Id @G..
2024.09.16 -
JPA 프록시에 사용하는 ByteBuddy
Lazy Loading(지연 로딩)을 하게 되면 연관 관계에 있는 엔터티 객체는 엔터티 객체를 상속받은 프록시 객체로 채워넣고 나중에 실제로 사용할 때 초기화 한다. 이 때 사용되는 프록시 라이브러리가 ByteBuddy이다. 이 프록시 객체를 Jackson에서 직렬화하려고 할 때 type 관련 에러가 발생하므로 연관 관계가 있는 엔터티를 RequestBody로 받는 것은 지양하자. ByteBuddyInterceptor 클래스의 경우 hibernate에서 제공하는 것으로 보인다.import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor;ByteBuddy란?컴파일러의 도움 없이 런타임에 자바 클래스를 생성 또는 수정하는 라이브러리이다.ByteBuddy를 ..
2024.09.14 -
Controller에서 Entity를 RequestBody로 받지 않는 이유?
@PutMappingpublic GenericResponse updateBanner(@RequestBody @Valid Banner banner) { bannerService.updateBanner(banner); return GenericResponse.success();}validation을 하는 경우 Entity에 @NotEmpty 와 같은 어노테이션이 들어가게 된다. 그런데 어떤 로직에서 이 Entity를 사용할 때 @NotEmpty 가 필요하지 않을 수도 있다.@NoArgsConstructor@AllArgsConstructor@Getter@Entitypublic class Banner { @Id @GeneratedValue(strategy = GenerationType.ID..
2024.09.14