问题描述
- hibenate 无法插入,能删除
- 错误如下:
type Exception reportmessage
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [entitle.Time2]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [entitle.Time2]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:630)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)
dao.TimeDaoImpl.insert(TimeDaoImpl.java:22)
biz.TimeBizImpl.insert(TimeBizImpl.java:19)
action.TimeAction.insert(TimeAction.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)daoimpl如下:public void insert(Time2 time) { // TODO Auto-generated method stub System.out.println(""insert.dao""); System.out.println(""long:""+time.getLong_()); super.getHibernateTemplate().save(time); //super.getHibernateTemplate().delete(time);}实体类如下:public class Time2 implements java.io.Serializable {// Fieldsprivate Integer id;private String long_;
数据库是mysql,,id为自增
能执行删除操作,可是新增操作就出错,,求助,谢谢。
解决方案
这个Time2怎么看起来这么别扭。
hibenate 中你设置主键生成策略是什么呢?
解决方案二:
dao.TimeDaoImpl.insert(TimeDaoImpl.java:22) 22行是什么??打断点看看