org.hibernate.tool.schema.spi.CommandAcceptanceException: 执行 DDL 创建 table 索引时出错
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL create table index
我正在尝试创建 table,但出现错误,我不知道为什么。我以为是因为浮动,但我的 Field table 有一个浮动并且正在正确生成。
我正在尝试更改方言或 create-drop 属性。但这对我没有帮助。所以我真的不知道该怎么办。
此外,我认为列排名是错误的原因,但我不知道为什么
错误:
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table index (id integer not null, lemma_id integer not null, page_id integer not null, rank float not null, primary key (id)) engine=MyISAM" 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:314)
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:318)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468)
at loader.Loader.main(Loader.java:22)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index (id integer not null, lemma_id integer not null, page_id integer not null,' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:762)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:646)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 11 more
休眠配置
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/search_engine?useSSL=false</property>
<property name="connection.username">root</property>
<property name="connection.password">roottoor</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">create-drop</property>
<mapping class="loader.scanner.Website"></mapping>
<mapping class="loader.entity.Field"></mapping>
<mapping class="loader.entity.Lemma"></mapping>
<mapping class="loader.entity.Index"></mapping>
</session-factory>
</hibernate-configuration>
索引实体
package loader.entity;
import javax.persistence.*;
@Entity
@Table(
name = "index"
)
public class Index {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(
name = "page_id",
nullable = false
)
private int pageId;
@Column(
name = "lemma_id",
nullable = false
)
private int lemmaId;
@Column(
nullable = false
)
private float rank;
public Index(int pageId, int lemmaId, float rank) {
this.pageId = pageId;
this.lemmaId = lemmaId;
this.rank = rank;
}
public Index(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPageId() {
return pageId;
}
public void setPageId(int pageId) {
this.pageId = pageId;
}
public int getLemmaId() {
return lemmaId;
}
public void setLemmaId(int lemmaId) {
this.lemmaId = lemmaId;
}
public float getRank() {
return rank;
}
public void setRank(float rank) {
this.rank = rank;
}
@Override
public String toString() {
return "Index{" +
"id=" + id +
", pageId=" + pageId +
", lemmaId=" + lemmaId +
", rank=" + rank +
'}';
}
}
Index 和 rank 是 SQL 中的保留关键字。尝试将其更改为其他内容。
但是如果你只想使用索引,那么使用下面的方法。
@Table(name = "\"index\"")
我正在尝试创建 table,但出现错误,我不知道为什么。我以为是因为浮动,但我的 Field table 有一个浮动并且正在正确生成。
我正在尝试更改方言或 create-drop 属性。但这对我没有帮助。所以我真的不知道该怎么办。
此外,我认为列排名是错误的原因,但我不知道为什么
错误:
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table index (id integer not null, lemma_id integer not null, page_id integer not null, rank float not null, primary key (id)) engine=MyISAM" 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:314)
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:318)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468)
at loader.Loader.main(Loader.java:22)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index (id integer not null, lemma_id integer not null, page_id integer not null,' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:762)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:646)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 11 more
休眠配置
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/search_engine?useSSL=false</property>
<property name="connection.username">root</property>
<property name="connection.password">roottoor</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">create-drop</property>
<mapping class="loader.scanner.Website"></mapping>
<mapping class="loader.entity.Field"></mapping>
<mapping class="loader.entity.Lemma"></mapping>
<mapping class="loader.entity.Index"></mapping>
</session-factory>
</hibernate-configuration>
索引实体
package loader.entity;
import javax.persistence.*;
@Entity
@Table(
name = "index"
)
public class Index {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(
name = "page_id",
nullable = false
)
private int pageId;
@Column(
name = "lemma_id",
nullable = false
)
private int lemmaId;
@Column(
nullable = false
)
private float rank;
public Index(int pageId, int lemmaId, float rank) {
this.pageId = pageId;
this.lemmaId = lemmaId;
this.rank = rank;
}
public Index(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPageId() {
return pageId;
}
public void setPageId(int pageId) {
this.pageId = pageId;
}
public int getLemmaId() {
return lemmaId;
}
public void setLemmaId(int lemmaId) {
this.lemmaId = lemmaId;
}
public float getRank() {
return rank;
}
public void setRank(float rank) {
this.rank = rank;
}
@Override
public String toString() {
return "Index{" +
"id=" + id +
", pageId=" + pageId +
", lemmaId=" + lemmaId +
", rank=" + rank +
'}';
}
}
Index 和 rank 是 SQL 中的保留关键字。尝试将其更改为其他内容。
但是如果你只想使用索引,那么使用下面的方法。
@Table(name = "\"index\"")