Domain object:
<hibernate-mapping>
<class name="Trade" table="Trades">
<id name="seqNum" column="SEQ_NUM" type="long" >
<generator class="sequence" >
<param name="sequence">trades_sequence</param>
</generator>
</id>
<propertyname="tradeId"column="Trade_Id"type="integer"/>
......
dao save function:
trade.setTradeId(nextTradeId)
getSessionFactory().getCurrentSession().saveOrUpdate(obj);
getSessionFactory().getCurrentSession().flush();
got excetion when save:
ConstraintViolationException
re save issue:
actually Trade.seqNum still get value after ConstraintViolationException, so when we resave this trade, hibernate will treat this trade as exist one, so it will just execute update sql instead of insert.
saveOrUpdate failed with new sequence number
原创
©著作权归作者所有:来自51CTO博客作者mb649d3a75b51a2的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
new thread 、 new stack和New Object的形象说明
e2 studio的使用
堆栈 Stack 网络协议栈 -
psql窗口函数 ROW_NUMBER的应用
psql窗口函数的使用
窗口函数 一对多 表结构 -
hdu Number Sequence
Number Sequence
Java #include Memory -
HDU 1711 Number Sequence
Problem Description
hdu kmp #include i++ ios