인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

김주현님의 프로필 이미지
김주현

작성한 질문수

자바 ORM 표준 JPA 프로그래밍 - 기본편

기본 키 매핑

현재 강의에서 em.persist 를 하는 이유가 정확하게 뭔가요?

작성

·

572

0

안녕하세요

강의를 들으면서 잘 모르겠는 부분이 있습니다. em.persist 를 하는 것인데요
해당 메소드는 이제 영속성 컨텍스트에 추가를 하기 위한 것으로 있는 것인가요?
다른 이유는 없나 궁금합니다.

답변 1

2

안녕하세요. 김주현님, 공식 서포터즈 OMG입니다.

알고 계신대로 persist()는 엔티티 매니저를 사용해서 엔티티를 영속성 컨텍스트에 저장합니다.

public interface EntityManager {

/**
* Make an instance managed and persistent.
* @param entity entity instance
* @throws EntityExistsException if the entity already exists.
* (If the entity already exists, the <code>EntityExistsException</code> may
* be thrown when the persist operation is invoked, or the
* <code>EntityExistsException</code> or another <code>PersistenceException</code> may be
* thrown at flush or commit time.)
* @throws IllegalArgumentException if the instance is not an
* entity
* @throws TransactionRequiredException if there is no transaction when
* invoked on a container-managed entity manager of that is of type
* <code>PersistenceContextType.TRANSACTION</code>
*/
public void persist(Object entity);


감사합니다.

김주현님의 프로필 이미지
김주현

작성한 질문수

질문하기