👉 기본 환경
- Language: Java
- DB: H2 Database
- IDE: IntelliJ
⌨️ 코드
Order Entity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
@Entity
public class Order {
@Id @GeneratedValue
private Long id;
private int orderAmount;
@Embedded
private Address address;
@ManyToOne
@JoinColumn(name = "PRODUCT_ID")
private Product product;
}
|
🖨️오류
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
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:439)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:423)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:374)
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:156)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1249)
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 jpql.Main.main(Main.java:11)
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-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.getSyntaxError(DbException.java:243)
at org.h2.command.Parser.readColumnIdentifier(Parser.java:4976)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4925)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4954)
at org.h2.command.Parser.parseAlterTable(Parser.java:7683)
at org.h2.command.Parser.parseAlter(Parser.java:6983)
at org.h2.command.Parser.parsePrepared(Parser.java:887)
at org.h2.command.Parser.parse(Parser.java:843)
at org.h2.command.Parser.parse(Parser.java:815)
at org.h2.command.Parser.prepareCommand(Parser.java:738)
at org.h2.engine.Session.prepareLocal(Session.java:657)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:278)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:183)
at java.base/java.lang.Thread.run(Thread.java:833)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
at org.h2.engine.SessionRemote.done(SessionRemote.java:611)
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:481)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 15 more
|
📡 원인
Order는 SQL의 키워드 중 하나이기 때문에 테이블 이름으로 사용 없음
📰 해결 방법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
@Entity
@Table(name = "ORDERS")
public class Order {
@Id @GeneratedValue
private Long id;
private int orderAmount;
@Embedded
private Address address;
@ManyToOne
@JoinColumn(name = "PRODUCT_ID")
private Product product;
}
|
Table name 별도 지정
'Java > JPA with Error' 카테고리의 다른 글
[해결 방법] javax.persistence.NonUniqueResultException (0) | 2023.09.22 |
---|---|
[해결 방법] javax.persistence.NoResultException (0) | 2023.09.22 |
[해결 방법] org.hibernate.QueryException (0) | 2023.09.20 |
[해결 방법] org.hibernate.exception.ConstraintViolationException (0) | 2023.09.19 |
[해결 방법] org.hibernate.MappingException (0) | 2023.09.13 |