작성
·
66
·
수정됨
0
기본 키 매핑 강의에서 @GeneratedValue의 전략 중 IDENTITY로 코드를 실행하니까
데이터베이스에서 member 테이블 자체가 사라지고 인서트 쿼리도 안 나갑니다. 뭐가 문제인지 모르겠네요ㅠㅠ
오류 코드는 다음과 같습니다.
8월 21, 2024 7:27:28 오후 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: hello]
8월 21, 2024 7:27:28 오후 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 6.4.2.Final
8월 21, 2024 7:27:28 오후 org.hibernate.cache.internal.RegionFactoryInitiator initiateService
INFO: HHH000026: Second-level cache disabled
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using built-in connection pool (not intended for production use)
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: Loaded JDBC driver class: org.h2.Driver
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001012: Connecting with JDBC URL [jdbc:h2:tcp://localhost/~/test]
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=sa}
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
8월 21, 2024 7:27:29 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH10001115: Connection pool size: 20 (min=1)
8월 21, 2024 7:27:29 오후 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)
8월 21, 2024 7:27:30 오후 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)
Hibernate:
drop table if exists Member cascade
8월 21, 2024 7:27:30 오후 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@3902bd2c] 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:
create table Member (
id varchar(255) generated by default as identity,
name varchar(255) not null,
primary key (id)
)
8월 21, 2024 7:27:31 오후 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@6ee99964] 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.
8월 21, 2024 7:27:31 오후 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "
create table Member (
id varchar(255) generated by default as identity,
name varchar(255) not null,
primary key (id)
)" via JDBC [Feature not supported: "CHARACTER VARYING(255)";]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "
create table Member (
id varchar(255) generated by default as identity,
name varchar(255) not null,
primary key (id)
)" via JDBC [Feature not supported: "CHARACTER VARYING(255)";]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:94)
at org.hibernate.tool.schema.internal.Helper.applySqlString(Helper.java:233)
at org.hibernate.tool.schema.internal.Helper.applySqlStrings(Helper.java:217)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createTables(SchemaCreatorImpl.java:420)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createSequencesTablesConstraints(SchemaCreatorImpl.java:340)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:239)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:172)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:142)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:118)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:256)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.lambda$process$5(SchemaManagementToolCoordinator.java:145)
at java.base/java.util.HashMap.forEach(HashMap.java:1421)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:142)
at org.hibernate.boot.internal.SessionFactoryObserverForSchemaExport.sessionFactoryCreated(SessionFactoryObserverForSchemaExport.java:37)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:315)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:450)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1507)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:55)
at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at hellojpa.JpaMain.main(JpaMain.java:9)
Caused by: org.h2.jdbc.JdbcSQLFeatureNotSupportedException: Feature not supported: "CHARACTER VARYING(255)"; SQL statement:
create table Member (
id varchar(255) generated by default as identity,
name varchar(255) not null,
[50100-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:568)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.message.DbException.getUnsupportedException(DbException.java:287)
at org.h2.command.ddl.SequenceOptions.getBounds(SequenceOptions.java:316)
at org.h2.command.ddl.SequenceOptions.getBounds(SequenceOptions.java:244)
at org.h2.schema.Sequence.<init>(Sequence.java:100)
at org.h2.table.Column.initializeSequence(Column.java:459)
at org.h2.command.ddl.CommandWithColumns.generateSequences(CommandWithColumns.java:103)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:113)
at org.h2.command.CommandContainer.update(CommandContainer.java:169)
at org.h2.command.Command.executeUpdate(Command.java:256)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:413)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:191)
at java.base/java.lang.Thread.run(Thread.java:833)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:568)
at org.h2.engine.SessionRemote.readException(SessionRemote.java:650)
at org.h2.engine.SessionRemote.done(SessionRemote.java:619)
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:237)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:262)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:80)
... 21 more
Hibernate:
/* insert for
hellojpa.Member */insert
into
Member (name, id)
values
(?, default)
8월 21, 2024 7:27:31 오후 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 42104, SQLState: 42S04
8월 21, 2024 7:27:31 오후 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table "MEMBER" not found (this database is empty); SQL statement:
/* insert for hellojpa.Member */insert into Member (name,id) values (?,default) [42104-224]
8월 21, 2024 7:27:31 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:h2:tcp://localhost/~/test]
Process finished with exit code 0
답변 2
0
안녕하세요, 인프런 AI 인턴입니다.
jinwoo2328님의 질문에 대한 답변입니다. 이러한 문제는 JPA를 사용하여 엔티티를 데이터베이스에 매핑할 때 발생할 수 있으며, @GeneratedValue(strategy = GenerationType.IDENTITY)
전략을 사용할 때 특히 그렇습니다. 여기서 문제는 H2 데이터베이스의 테이블 생성 문법과 JPA가 생성하는 DDL(데이터 정의 언어) 간의 불일치로 발생한 것 같습니다.
이 문제와 유사한 경우에 대한 해결 방법은 아래 링크에서 찾을 수 있습니다:
예를 들어 H2 데이터베이스 버전이나 설정이 엔티티의 ID 구성과 충돌하는 경우가 있습니다. 이를 해결하기 위한 방법 중 하나는 H2 데이터베이스의 버전을 변경하거나, application.properties
에서 spring.datasource.url
에 추가 옵션을 포함시켜 호환성을 높이는 것입니다.
jinwoo2328님의 오류 로그를 보면, CHARACTER VARYING(255)
이 지원되지 않는다는 메시지가 나옵니다. 이는 특정 H2 버전에서 @GeneratedValue(strategy = GenerationType.IDENTITY)
와 연관된 문제일 수 있습니다. 따라서 지식공유자님이 제공한 링크에서 제시한 해결책을 시도해 보시길 바랍니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.