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> 展开
三月 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> 展开
2个回答
展开全部
你试试看,你的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的吗?看看是不是对的上,估计这里有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误处 代码贴出来塞
更多追问追答
追问
session.save(input);就是这里出了错
追答
那这个就应该是 配置 问题了...hibernate 配置贴出来, 包括 实体类配置
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询