s2sh中关于使用hibernate添加用户的情况
我有三张表,一张表示用户表,属性为username(主键,varchar型)和password(varchar);第二张表为blackhole主键为blackholeid(int型),username(外键),blackholecontent(varchar),datetime(datetime);还有一张joke表和blackhole差不多。我的dao层继承了HibernateDaoSupport并使用了getHibernateTemplate().save(user),结果报了如下错误:
Hibernate operation: could not insert: [com.model.User]; uncategorized SQLException for SQL [insert into blackhole.user (password) values (?)]; SQL state [HY000]; error code [1364]; Field 'username' doesn't have a default value; nested exception is java.sql.SQLException: Field 'username' doesn't have a default value
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [com.model.User]; uncategorized SQLException for SQL [insert into blackhole.user (password) values (?)]; SQL state [HY000]; error code [1364]; Field 'username' doesn't have a default value; nested exception is java.sql.SQLException: Field 'username' doesn't have a default value
java.sql.SQLException: Field 'username' doesn't have a default value
[解决办法]
删除user.hbm.xml中username配置的 <generator class="native" />
[解决办法]