我在嘗試使用Springs默認存儲庫嘗試保留對象時出現某些問題,因此遇到了一些問題。我使用hibernate作爲我的持久層和Spring MVC框架。我使用JPA而不是hibernate映射文件。SQL錯誤:1366錯誤的整數值Spring MVC休眠
我看到的錯誤是:
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 1366, SQLState: HY000
ERROR: org.hibernate.util.JDBCExceptionReporter - Incorrect integer value: '\xAC\xED\x00\x05sr\x00!com.kwhours.butternut.domain.Type\xCF;\xBF\xEF\x8A\x82\x87\xF1\x02\x00\x0DZ\x00\x06isLeafI\x00\x05levelL\' for column 'type_id' at row 1
我試圖堅持域對象與JPA註釋代碼的相關部分是:
@Entity
@Table(name = "question")
public class Question implements java.io.Serializable {
private Type type;
@Column(name = "type_id")
public Type getType() {
return this.type;
}
public void setType(Type type) {
this.type = type;
}
}
我有個外國關鍵約束在question.type_id列正確設置爲type.id列。我能夠讓我的對象在代碼中正確表示,但是當我嘗試使以下存儲庫保持該對象時,我得到了前面提到的錯誤。
public interface QuestionRepository extends CrudRepository<Question, Long> {
public List<Question> findByDatasetInstanceId(Long datasetInstanceId);
}
所以要清楚。我可以創建一個新的問題對象,並使用存儲庫從數據庫中檢索一個類型對象。我可以將questions.type設置爲這個新的類型對象,但是當我嘗試使用上面的存儲庫持久保存包含該類型的問題時,我會得到該錯誤。我在調試器中檢出了類型對象,似乎沒有什麼不妥之處。任何線索或建議都很有幫助。這看起來像某種逃生字符序列,但我不太確定。
http://stackoverflow.com/questions/2762416/can not-insert-non-latin-symbols-in-mysql – invariant
它試圖插入類型對象的id,是數據庫中的Java Long和Bigint(20)。沒有字符串在這裏編碼不正確,並且由於數據庫自動增量而創建了id,所以我懷疑mysql是否在編碼中創建了id,它不能讀取:)。 – flips
請同時發佈'Type'類。 –