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

fecorp님의 프로필 이미지
fecorp

작성한 질문수

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

다대다 [N:M]

다대다 매핑을 할 때 오류입니다.

작성

·

322

0

다대다 매핑을 하면서 create부분에서 오류가나는데 검색을 해봐도 잘 나오지 않아서 문의드립니다.

 

9월 29, 2021 10:47:19 오전 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection

INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@38d17d80] 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.

9월 29, 2021 10:47:19 오전 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException

WARN: GenerationTarget encountered exception accepting command : Error executing DDL "

    drop table Order if exists" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "

    drop table Order if exists" via JDBC Statement

at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126)

at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)

at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144)

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:14)

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "

    DROP TABLE ORDER[*] IF EXISTS "; expected "identifier"; SQL statement:

 

    drop table Order if exists [42001-199]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)

at org.h2.message.DbException.getSyntaxError(DbException.java:243)

at org.h2.command.Parser.readColumnIdentifier(Parser.java:4530)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4491)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4508)

at org.h2.command.Parser.parseDrop(Parser.java:2113)

at org.h2.command.Parser.parsePrepared(Parser.java:860)

at org.h2.command.Parser.parse(Parser.java:788)

at org.h2.command.Parser.parse(Parser.java:760)

at org.h2.command.Parser.prepareCommand(Parser.java:683)

at org.h2.engine.Session.prepareLocal(Session.java:627)

at org.h2.server.TcpServerThread.process(TcpServerThread.java:270)

at org.h2.server.TcpServerThread.run(TcpServerThread.java:175)

at java.base/java.lang.Thread.run(Thread.java:834)

 

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.engine.SessionRemote.done(SessionRemote.java:607)

at org.h2.command.CommandRemote.prepare(CommandRemote.java:85)

at org.h2.command.CommandRemote.<init>(CommandRemote.java:51)

at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:477)

at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292)

at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)

at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)

at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)

... 15 more

 

9월 29, 2021 10:47:19 오전 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection

INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@5fa23c] 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.

9월 29, 2021 10:47:19 오전 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException

WARN: GenerationTarget encountered exception accepting command : Error executing DDL "

    create table Order (

       id bigint not null,

        count integer not null,

        price integer not null,

        MEMBER_ID bigint,

        PRODUCT_ID bigint,

        primary key (id)

    )" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "

    create table Order (

       id bigint not null,

        count integer not null,

        price integer not null,

        MEMBER_ID bigint,

        PRODUCT_ID bigint,

        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:14)

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "

    CREATE TABLE ORDER[*] (

       ID BIGINT NOT NULL,

        COUNT INTEGER NOT NULL,

        PRICE INTEGER NOT NULL,

        MEMBER_ID BIGINT,

        PRODUCT_ID BIGINT,

        PRIMARY KEY (ID)

    ) "; expected "identifier"; SQL statement:

 

    create table Order (

       id bigint not null,

        count integer not null,

        price integer not null,

        MEMBER_ID bigint,

        PRODUCT_ID bigint,

        primary key (id)

    ) [42001-199]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)

at org.h2.message.DbException.getSyntaxError(DbException.java:243)

at org.h2.command.Parser.readColumnIdentifier(Parser.java:4530)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4491)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4508)

at org.h2.command.Parser.parseCreateTable(Parser.java:7814)

at org.h2.command.Parser.parseCreate(Parser.java:5818)

at org.h2.command.Parser.parsePrepared(Parser.java:846)

at org.h2.command.Parser.parse(Parser.java:788)

at org.h2.command.Parser.parse(Parser.java:760)

at org.h2.command.Parser.prepareCommand(Parser.java:683)

at org.h2.engine.Session.prepareLocal(Session.java:627)

at org.h2.server.TcpServerThread.process(TcpServerThread.java:270)

at org.h2.server.TcpServerThread.run(TcpServerThread.java:175)

at java.base/java.lang.Thread.run(Thread.java:834)

 

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.engine.SessionRemote.done(SessionRemote.java:607)

at org.h2.command.CommandRemote.prepare(CommandRemote.java:85)

at org.h2.command.CommandRemote.<init>(CommandRemote.java:51)

at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:477)

at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292)

at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)

at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)

at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)

... 15 more

 

9월 29, 2021 10:47:19 오전 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException

WARN: GenerationTarget encountered exception accepting command : Error executing DDL "

    alter table Order 

       add constraint FK1p7tdl9cjebkwla71ec3cu3oa 

       foreign key (MEMBER_ID) 

       references Member" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "

    alter table Order 

       add constraint FK1p7tdl9cjebkwla71ec3cu3oa 

       foreign key (MEMBER_ID) 

       references Member" 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:375)

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:14)

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "

    ALTER TABLE ORDER[*] 

       ADD CONSTRAINT FK1P7TDL9CJEBKWLA71EC3CU3OA 

       FOREIGN KEY (MEMBER_ID) 

       REFERENCES MEMBER "; expected "identifier"; SQL statement:

 

    alter table Order 

       add constraint FK1p7tdl9cjebkwla71ec3cu3oa 

       foreign key (MEMBER_ID) 

       references Member [42001-199]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)

at org.h2.message.DbException.getSyntaxError(DbException.java:243)

at org.h2.command.Parser.readColumnIdentifier(Parser.java:4530)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4491)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4508)

at org.h2.command.Parser.parseAlterTable(Parser.java:7201)

at org.h2.command.Parser.parseAlter(Parser.java:6546)

at org.h2.command.Parser.parsePrepared(Parser.java:828)

at org.h2.command.Parser.parse(Parser.java:788)

at org.h2.command.Parser.parse(Parser.java:760)

at org.h2.command.Parser.prepareCommand(Parser.java:683)

at org.h2.engine.Session.prepareLocal(Session.java:627)

at org.h2.server.TcpServerThread.process(TcpServerThread.java:270)

at org.h2.server.TcpServerThread.run(TcpServerThread.java:175)

at java.base/java.lang.Thread.run(Thread.java:834)

 

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.engine.SessionRemote.done(SessionRemote.java:607)

at org.h2.command.CommandRemote.prepare(CommandRemote.java:85)

at org.h2.command.CommandRemote.<init>(CommandRemote.java:51)

at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:477)

at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292)

at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)

at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)

at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)

... 15 more

 

9월 29, 2021 10:47:19 오전 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException

WARN: GenerationTarget encountered exception accepting command : Error executing DDL "

    alter table Order 

       add constraint FKiqsf200773nxdox2df2woemp5 

       foreign key (PRODUCT_ID) 

       references Product" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "

    alter table Order 

       add constraint FKiqsf200773nxdox2df2woemp5 

       foreign key (PRODUCT_ID) 

       references Product" 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:375)

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:14)

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "

    ALTER TABLE ORDER[*] 

       ADD CONSTRAINT FKIQSF200773NXDOX2DF2WOEMP5 

       FOREIGN KEY (PRODUCT_ID) 

       REFERENCES PRODUCT "; expected "identifier"; SQL statement:

 

    alter table Order 

       add constraint FKiqsf200773nxdox2df2woemp5 

       foreign key (PRODUCT_ID) 

       references Product [42001-199]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)

at org.h2.message.DbException.getSyntaxError(DbException.java:243)

at org.h2.command.Parser.readColumnIdentifier(Parser.java:4530)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4491)

at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4508)

at org.h2.command.Parser.parseAlterTable(Parser.java:7201)

at org.h2.command.Parser.parseAlter(Parser.java:6546)

at org.h2.command.Parser.parsePrepared(Parser.java:828)

at org.h2.command.Parser.parse(Parser.java:788)

at org.h2.command.Parser.parse(Parser.java:760)

at org.h2.command.Parser.prepareCommand(Parser.java:683)

at org.h2.engine.Session.prepareLocal(Session.java:627)

at org.h2.server.TcpServerThread.process(TcpServerThread.java:270)

at org.h2.server.TcpServerThread.run(TcpServerThread.java:175)

at java.base/java.lang.Thread.run(Thread.java:834)

 

at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

at org.h2.engine.SessionRemote.done(SessionRemote.java:607)

at org.h2.command.CommandRemote.prepare(CommandRemote.java:85)

at org.h2.command.CommandRemote.<init>(CommandRemote.java:51)

at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:477)

at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292)

at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)

at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)

at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)

... 15 more

 

오류는 이부분이고 H2버전을 낮추라고 해서 버전을 낮췄는데도 같은 오류가 나서 Order 부분이 문제인거 같습니다.

[ Member. class ]

@Entity
public class Member {

@Id @GeneratedValue
@Column(name = "MEMBER_ID")
private Long id;

@Column(name="USERNAME")
private String username;

@OneToMany(mappedBy = "member")
private List<Order> orders = new ArrayList<>();

}

 

[ Order.class ]

@Entity
public class Order {

@Id @GeneratedValue
private Long id;

@ManyToOne
@JoinColumn(name = "MEMBER_ID")
private Member member;

@ManyToOne
@JoinColumn(name = "PRODUCT_ID")
private Product product;

private int count;
private int price;

}

답변 3

1

fecorp님의 프로필 이미지
fecorp
질문자

와... 정말 감사합니다!! 드디어 해결되었네요
진심으로 감사드립니다 David님

0

fecorp님의 프로필 이미지
fecorp
질문자

참고한 자료를 모두 시도했으나 같은 오류가 발생해서 문의드립니다.

https://github.com/MrPPak/ex1-hello-jpa

여기있는 코드대로 했고 문제의 코드는 Member, Order, Product부분입니다.

한번 확인해주시면 정말 감사하겠습니다.

Order가 H2에서는 예약어로 잡혀있네요.

강의 내에서 작성된 것처럼 Order 대신 MemberProduct으로 이름을 변경하여 진행해주세요.

https://stackoverflow.com/questions/46737430/hibernate-h2-embeddable-list-expected-identifier

0

안녕하세요. fecorp님, 공식 서포터즈 David입니다.

.
h2에 접속하셔서 기존에 생성된 테이블을 모두 제거한 뒤 다시 시도해보시겠어요?

그래도 안 되신다면 아래 글을 참고하셔서 Hibernate 버전을 올려서 프로젝트에 적용하신 뒤 다시 시도해주세요.

https://www.inflearn.com/questions/52796
.
감사합니다.

fecorp님의 프로필 이미지
fecorp

작성한 질문수

질문하기