【发布时间】:2016-01-12 03:48:59
【问题描述】:
这是场景
@Transient
private Map<String, String> choices = null;
@Column(name = "choices", nullable = false)
public String getChoices() {
return gson.toJson(choices);
}
在插入记录时它说
java.sql.SQLException: 字段 'choices' 没有默认值
我的调试 SQL
DEBUG SQL:109 -
insert
into
question
(description, id)
values
(?, ?)
此处的选项字段被忽略。
数据库详情:
CREATE TABLE `question` (<br/>
`id` varchar(50) COLLATE utf8_bin NOT NULL,<br/>
`description` varchar(1000) COLLATE utf8_bin NOT NULL,<br/>
`choices` text COLLATE utf8_bin NOT NULL,<br/>
`answers` varchar(100) COLLATE utf8_bin NOT NULL<br/>
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;<br/>
<br/>
ALTER TABLE `question`<br/>
ADD PRIMARY KEY (`id`);<br/>
有人可以帮助我为什么忽略这些字段吗? 谢谢。
[更新] 实体类:
@Entity
@Table(name = "question")
public class Question {
@Id
private String id = null;
@Column(name = "description", nullable = false)
private String description = null;
@Transient
@Column(name = "choices", nullable = false)
private Map<String, String> choices = null;
public String getChoices() {
return gson.toJson(choices);
}
@Transient
private Set<String> answers = null;
@Transient
private Gson gson = new GsonBuilder().create();
public Question() {
this.id = UUID.randomUUID().toString();
}
...
}//End of class
【问题讨论】:
标签: java mysql spring hibernate jpa