我正在使用MySQL数据库和 Spring Data。每次我尝试保存数据时,都会出错
2019-07-16 15:35:54.590 WARN 8972 --- [nio-8090-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1364, SQLState: HY000
2019-07-16 15:35:54.591 ERROR 8972 --- [nio-8090-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : Field 'ImagePath' doesn't have a default value
org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
编译后出现此错误后,我发现数据库中添加了两个新实体:“image_path”和“upload_date”。我没有写任何代码来做这样的事情。
我再次编译以查看 image_path 列已插入 ImagePath 实体应该插入的数据。
实体
@Entity
@Table(name="photo")
public class Photo {
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name="albumID")
private int albumID;
@Column(name="LocationID")
private int locationID;
@Column(name="Title")
private String title;
@Column(name="Description")
private String description;
@Column(name="UploadDate")
private Timestamp uploadDate;
@Column(name="ImagePath")
private String imagePath;
*ommited getters and setters for abbreviation*
}
百里香叶形式
<form action="#" th:action="@{/addPost}" th:object="${photo}" method="post" enctype="multipart/form-data">
Select File: <input type="file" name="file"/>
<input type="text" th:field="*{title}" class="form-control mb-4 col-4" placeholder="Title of the Photo">
<input type="text" th:field="*{description}" class="form-control mb-4 col-4" placeholder="Description">
<input type="submit" value="Upload File"/>
</form>
为什么在数据库中自动创建两个新列?
我希望新的传入数据保存在带注释的“ImagePath”和“UploadDate”列中,而不是保存在它自己创建的新“image_path”和“upload_date”列中。
繁星coding
相关分类