我正在使用MySQL數(shù)據(jù)庫(kù)和 Spring Data。每次我嘗試保存數(shù)據(jù)時(shí),都會(huì)出錯(cuò)2019-07-16 15:35:54.590 WARN 8972 --- [nio-8090-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1364, SQLState: HY0002019-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 valueorg.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement編譯后出現(xiàn)此錯(cuò)誤后,我發(fā)現(xiàn)數(shù)據(jù)庫(kù)中添加了兩個(gè)新實(shí)體:“image_path”和“upload_date”。我沒(méi)有寫(xiě)任何代碼來(lái)做這樣的事情。我再次編譯以查看 image_path 列已插入 ImagePath 實(shí)體應(yīng)該插入的數(shù)據(jù)。實(shí)體@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> 為什么在數(shù)據(jù)庫(kù)中自動(dòng)創(chuàng)建兩個(gè)新列?我希望新的傳入數(shù)據(jù)保存在帶注釋的“ImagePath”和“UploadDate”列中,而不是保存在它自己創(chuàng)建的新“image_path”和“upload_date”列中。
Spring Data 不保存在帶注釋的列名中
慕工程0101907
2023-03-31 09:20:10