SQL异常:无法准备语句

时间:2017-11-07 15:46:00

标签: java sql spring hibernate jpa

我正在学习Spring启动,当我想创建一个我不理解的“Lot”时,我有一些例外。

** Utilisateur entity **

@JsonIgnoreProperties
@Entity
@Data
public class Utilisateur {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private String nom;

@Column
private String prenom;

@Column
private String adresse;

@Column
private String numeroTelephone;

@Column
private String email;

@OneToMany(cascade = CascadeType.ALL)
private List<Lot> lotList;

@OneToMany(cascade = CascadeType.ALL)
private List<Tentative> tentativeList;

}

“utilisateur”(表示用户)与n“Lot”(表示奖品)相关,并且每天可以进行三次尝试(“暂定”)。

**地块实体**

@JsonIgnoreProperties
@Entity
@Data
public class Lot {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@Column(name = "nom")
private String nom;

@NotNull
@Column(name = "description")
private String description;

@Column(name = "date_time_declenchement")
private LocalDateTime dateTimeDeclenchement;

@NotNull
@Column(name = "is_gagne")
private boolean isGagne;

@ManyToOne(cascade = CascadeType.ALL)
private Utilisateur utilisateur;

}

**暂定实体**

@JsonIgnoreProperties
@Entity
@Data
public class Tentative {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@Column
private LocalDateTime dateTentative;

@ManyToOne(cascade = CascadeType.ALL)
private Utilisateur utilisateur;
}

我的create.sql!

CREATE TABLE Utilisateur
(
 id INT PRIMARY KEY AUTO_INCREMENT,
 nom VARCHAR(100) NOT NULL,
 prenom VARCHAR(100) NOT NULL,
 adresse VARCHAR(100) NOT NULL,
 numero_telephone VARCHAR(100) NOT NULL,
 email VARCHAR(100) NOT NULL UNIQUE,
);

CREATE TABLE Lot
(
 id INT PRIMARY KEY AUTO_INCREMENT,
 nom VARCHAR(100) NOT NULL,
 description VARCHAR(255) NOT NULL,
 date_time_declenchement DATE,
 is_gagne BOOLEAN NOT NULL,
);

CREATE TABLE Tentative
(
 id INT PRIMARY KEY AUTO_INCREMENT,
 id_utilisateur INT,
 id_lot INT,
 date_tentative DATE NOT NULL,
);

ALTER TABLE Tentative
ADD CONSTRAINT fk_id_utilisateur_tentative FOREIGN KEY (id_utilisateur) 
REFERENCES Utilisateur(id);

ALTER TABLE Tentative
ADD CONSTRAINT fk_id_lot_tentative FOREIGN KEY (id_lot) REFERENCES Lot(id);

当我想用身体创造一个“很多”时:

{
 "nom":"TV Samsung",
 "description":"Télévision Plasma Samsung 106cm"
}

我得到了这个例外:

{
"timestamp": 1510068319912,
"status": 500,
"error": "Internal Server Error",
"exception": 
"org.springframework.dao.InvalidDataAccessResourceUsageException",
    "message": "could not prepare statement; SQL [insert into lot (id, 
date_time_declenchement, description, is_gagne, nom, utilisateur_id) values 
(null, ?, ?, ?, ?, ?)]; nested exception is 
org.hibernate.exception.SQLGrammarException: could not prepare statement",
    "path": "/creerlot"
}

我不明白为什么我会犯这个错误。第一,我只用hibernate / Jpa完成了我的项目。使用CRUDRepository接口,很容易找到/保存我的对象。 但是现在我有了sql,我的所有方法都会返回一个异常,除了我创建一个“Utilisateur”的方法。

谢谢大家!

0 个答案:

没有答案