我真的被困在这里,需要帮助,我一直在尝试运行我的应用程序,让休眠状态使用我的java实体创建表,但是它不断引发此异常:
无法对JDBC目标执行架构管理[创建表答案(id_answer bigint不为null的auto_increment,订单整数,文本varchar(255),question_id_question bigint,主键(id_answer))]
说我的SQL语法有错误,即使我没有编写任何sql,我也让休眠处理了这一切。
以下是我的课程和配置:
Answer.java:
package com.sfm.elearn.business.entities;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class Answer implements Serializable {
@Id @GeneratedValue
private Long idAnswer;
private String text;
private Integer order;
@ManyToOne
@JsonIgnore
private Question question;
public Answer() {
super();
// TODO Auto-generated constructor stub
}
public Answer(String text, Integer order, Question question) {
super();
this.text = text;
this.order = order;
this.question = question;
}
public Long getIdAnswer() {
return idAnswer;
}
public void setIdAnswer(Long idAnswer) {
this.idAnswer = idAnswer;
}
}
这是我的配置:
spring.datasource.url=jdbc:mysql://localhost:3306/ElearningBase
spring.datasource.username=root
spring.datasource.password=654321
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
编辑:我发现了错误,属性“ order”是导致错误的原因,它是保留的SQL关键字,更改变量名称即可解决问题!
答案 0 :(得分:0)
如果Hibernate正在为您创建表,则应将hibernate.ddl-auto属性设置为'create'或'create-drop'。更新选项意味着Hibernate希望您的表已经存在。参见:Hibernate hbm2ddl.auto possible values and what they do?