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

김민희님의 프로필 이미지
김민희

작성한 질문수

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

Hello JPA - 애플리케이션 개발

DB에 저장이 안됩니다

해결된 질문

작성

·

495

0

java 코드


public class JpaMain {

    public static void main(String[] args) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");
        EntityManager em = emf.createEntityManager();


        //code
        EntityTransaction tx = em.getTransaction();
        tx.begin();

        Member member = new Member();
        member.setId(1L);
        member.setName("mini");
        em.persist(member); // member를 저장

        tx.commit();

        em.close();
        emf.close();
    }
}

로그

1월 26, 2024 4:43:27 오후 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation

INFO: HHH000204: Processing PersistenceUnitInfo [name: hello]

1월 26, 2024 4:43:28 오후 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate ORM core version 6.4.2.Final

1월 26, 2024 4:43:28 오후 org.hibernate.cache.internal.RegionFactoryInitiator initiateService

INFO: HHH000026: Second-level cache disabled

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

WARN: HHH10001002: Using built-in connection pool (not intended for production use)

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001005: Loaded JDBC driver class: org.h2.Driver

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001012: Connecting with JDBC URL [jdbc:h2::tcp://localhost/~/jpa-exercise]

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001001: Connection properties: {password=****, user=sa}

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001003: Autocommit mode: false

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>

INFO: HHH10001115: Connection pool size: 20 (min=1)

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl constructDialect

WARN: HHH90000025: H2Dialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)

1월 26, 2024 4:43:28 오후 org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService

INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)

1월 26, 2024 4:43:28 오후 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection

INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@7f7b6639] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.

1월 26, 2024 4:43:28 오후 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection

INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@2abbd0d9] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.

Hibernate:

drop table if exists Member cascade

Hibernate:

create table Member (

id bigint not null,

name varchar(255),

primary key (id)

)

Hibernate:

/* insert for

hellojpa.Member */insert

into

Member (name, id)

values

(?, ?)

1월 26, 2024 4:43:28 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop

INFO: HHH10001008: Cleaning up connection pool [jdbc:h2::tcp://localhost/~/jpa-exercise]

Process finished with exit code 0

insert 로그도 찍히는데 왜 안들어갈까요...?

답변 1

0

김민희님의 프로필 이미지
김민희
질문자

참고)
Member 클래스에

 @Override
    public String toString() {
        return "Member [id=" + id + ", name=" + name + " ]";
    }

추가하고 커밋한 뒤에

        Member retrievedMember = em.find(Member.class, 1L);
        System.out.println("Retrieved Member: " + retrievedMember);

조회해봤을때

Retrieved Member: Member [id=1, name=mini ]

이렇게 잘 나오네요. 무가 문제일까요...?

김민희님의 프로필 이미지
김민희

작성한 질문수

질문하기