반응형 isnew2 [JPA] save 시 select 쿼리 발생 (Persistable 의 isNew 사용) 이전 포스팅에서 dirty checking 관련해서 글을 다룬적이 있다. 자세한 내용은 아래 참고 포스팅을 참고 바란다. 엔티티를 가지고 작업을 하게 될 경우 매번 select 을 하고 update를 하거나 insert 를 할때 더티 체킹을 한다면 만약 bulk insert를 jpa에서 하게 될 경우엔 어떻게 해야할까? 별도의 작업이 없이 읽어서 insert를 하기만 하면된다. 코드는 아래와 같이 간단하다. TestTable ent = TestTable.builder() .id(id) .nameValue("test") .gender(1) .build(); repo.save(ent); 이대로 실행을 하면 [interceptor] requestURI : /test/entitysetnew Hibernate: .. 2024. 2. 7. isNew method JPA에서 save 를 할 경우 persistence 상태에 따라서 insert 가 되거나 update 가 되게한다. save에 대한 내용은 아래 참고 포스팅 참고 바란다. 이 역할을 하는것이 isNew 메서드 이다. JPA에 기본적으로 구현되어있는 save 메서드를 보게 되면 @Transactional @Override public S save(S entity) { Assert.notNull(entity, "Entity must not be null."); if (entityInformation.isNew(entity)) { em.persist(entity); return entity; } else { return em.merge(entity); } } 상태에 따라 persis를 하거나 merge를 하.. 2022. 12. 12. 이전 1 다음 반응형