hibernate插入数据报错 求高手指点 5

Hibernate:insertintoManagement.dbo.inoutPut(cardNum,userName,time,Input,img)values(?,... Hibernate: insert into Management.dbo.inoutPut (cardNum, userName, time, Input, img) values (?, ?, ?, ?, ?)
三月 15, 2013 2:13:24 下午 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 0, SQLState: null
三月 15, 2013 2:13:24 下午 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: 只有运行该语句,生成的键才会可用。
三月 15, 2013 2:13:24 下午 org.hibernate.AssertionFailure <init>
严重: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in model.InoutPut entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at video.VideoFrame.selxx(VideoFrame.java:698)
at video.VideoFrame$1.keyPressed(VideoFrame.java:880)
at java.awt.Component.processKeyEvent(Component.java:6463)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2829)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1893)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:752)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1017)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:889)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:717)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
<hibernate-mapping>
<class catalog="Management" name="model.InoutPut" schema="dbo" table="inoutPut">
<id name="id" type="int">
<column name="id"/>
<generator class="native"/>
</id>
<many-to-one class="model.Staff" fetch="select" name="staff">
<column length="50" name="cardNum"/>
</many-to-one>
<property name="userName" type="string">
<column length="50" name="userName"/>
</property>
<property name="time" type="timestamp">
<column length="50" name="time"/>
</property>
<property name="input" type="string">
<column length="50" name="Input"/>
</property>
<property name="img" type="binary">
<column name="img"/>
</property>
</class>
</hibernate-mapping>
展开
 我来答
百度网友1bda90078f
2013-03-15 · 超过16用户采纳过TA的回答
知道答主
回答量:69
采纳率:0%
帮助的人:49.4万
展开全部
你试试看,你的id设置的是主键但是是native的,代表是自己给值,你插入数据库的时候没有给id赋值,如果你是mysql数据库,在配置文件中吧id设置成increment
更多追问追答
追问
我用的是sqlserver2005  id字段在数据库中使用了递增的
追答
哦,hibernate有段时间没有接触了,记不清了,这是你的报错语句org.hibernate.AssertionFailure: null id in model.InoutPut entry (don't flush the Session after an exce。你查查sqlserver的hibernate的id策略是什么,不知道是不是native,还有可能是你的id的数据类型,都是int的吗?看看是不是对的上,估计这里有问题
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
tangsuqq
2013-03-15 · TA获得超过369个赞
知道答主
回答量:297
采纳率:0%
帮助的人:65.8万
展开全部
错误处 代码贴出来塞
更多追问追答
追问
session.save(input);就是这里出了错
追答
那这个就应该是 配置 问题了...hibernate 配置贴出来, 包括 实体类配置
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式