작성
·
722
0
환경
1. h2 version 1.4.199
2. JPA 하이버네이트 5.3.10.Final
3. <property name="hibernate.hbm2ddl.auto" value="create"/>
Member.class
package hellojpa;
import javax.persistence.*;
@Entity
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@Column(name = "name", nullable = false)
private String username;
public Member() {
}
public Member(String id, String username) {
this.id = id;
this.username = username;
}
/**
* getter setter
*/
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
JpaMain.java
package hellojpa;
import javax.persistence.*;
@Entity
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@Column(name = "name", nullable = false)
private String username;
public Member() {
}
public Member(String id, String username) {
this.id = id;
this.username = username;
}
/**
* getter setter
*/
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
에러코드
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 Statement
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 Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at hellojpa.JpaMain.main(JpaMain.java:10)
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-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:575)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
at org.h2.message.DbException.get(DbException.java:227)
at org.h2.message.DbException.get(DbException.java:203)
at org.h2.message.DbException.getUnsupportedException(DbException.java:291)
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:101)
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:110)
at org.h2.command.CommandContainer.update(CommandContainer.java:174)
at org.h2.command.Command.executeUpdate(Command.java:252)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:408)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:191)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:507)
at org.h2.engine.SessionRemote.done(SessionRemote.java:611)
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:237)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:228)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 15 more
답변 2
1.4.200 버전으로 수정하였으나 Identity 타입으로는 여전히 아래의 문제가 발생합니다.
== 추가 답변 ==
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/~/test;MODE=LEGACY"/>
를 통해 수정해 문제를 해결하였습니다.
해결하였습니다.
스택오버플로우에서는 1.4.200 버전에 취약성이 있어서 그렇다고 하네요
1
저와 비슷한 이슈로 고생하시는 분들을 위해 Create 테이블 및 Insert 쿼리 이슈 해결과정 링크 남깁니다.
https://abcdefgh123123.tistory.com/470
테이블은 만들어지나, 와같은 에러가 발생하며 데이터가 DB에 들어가지 않습니다.
===== 추가 답변 ====
GenerateType을 AUTO로 바꾸어주니 해결되었습니다. 혹시 앞서
를 알 수 있을까요?