首页 > 其他分享 >saveOrUpdate failed with new sequence number

saveOrUpdate failed with new sequence number

时间:2023-07-03 10:00:50浏览次数:39  
标签:saveOrUpdate sequence getCurrentSession trade failed getSessionFactory save

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,sequence,getCurrentSession,trade,failed,getSessionFactory,save
From: https://blog.51cto.com/u_16174476/6609046

相关文章

  • Failed to copy artifact. Failed to install artifact-\target\classes (Access is
    Failedtocopyartifact.Failedtoinstallartifact-\target\classes(Accessisdenied)<!--<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.3.2</version&......
  • YetAnotherRGBSequence
    [ABC266G]YetAnotherRGBSequence为了方便将\(r,g,b\)替换为\(a,b,c\)。考虑可以将\(a-=k,b-=k\),就变为\(a-k\)个\(a\),\(b-k\)个\(b\),\(c\)个\(c\),\(k\)个\(ab\),(这里我们已经将\(a,b\)减去\(k\),下文的\(a,b\)均指代减去后的结果)然后求排列总数,使得不构成新......
  • 部署java的linux服务器远程报错:[USM] Channel request shell failed
    问题部署很多个微服务的linux服务器ssh远程突然进不去,远程工具提示:[USM]Channelrequestshellfailed排查分析因为部署的是很多个java进程,有可能线程数占满导致系统可创建线程耗尽,排查步骤如下:使用非远程方式进入服务器,使用top-H命令查看系统创建的线程数:查看系统允许创......
  • qt this application failed to start because it could notfoind orloadthe Qt pla
    qt程序报错:thisapplicationfailedtostartbecauseitcouldnotfoind orloadtheQt platform ===================================C:\Users\lenovo>C:\Users\lenovo>C:\Users\lenovo>cdD:\software\Qt\install\Qt5_12_12\5.12.12\msvc2015_64\b......
  • 启动mysql时报错Failed to start mysqld.service: Unit not found
    问题描述:启动mysql时报错Failedtostartmysqld.service:Unitnotfound,如下所示:数据库:mysql5.7.42系统:rhel7.31、问题重现--mysql安装过程[root@leo-mysql-master~]#yumlocalinstallhttps://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm[root@leo......
  • vue列表页返回数组错误Invalid prop: type check failed for prop "data". Expected A
    一个vue列表页接收后端数组时是这样写的:this.list=response.data返回如下错误:Invalidprop:typecheckfailedforprop"data".ExpectedArray,gotObject意思是希望返回一个数组但实际得到一个对象Object,网上大多是初始化userList=[]或userList=null解决的,但......
  • Jmeter访问网站返回403(CSRF verification failed. Request aborted.)
    django网站自带CSRF校验,所以jmeter直接请求时会出现校验不通过的情况一、CSRF校验CSRF是指跨站请求伪造,CSRF攻击的流程大概是我们登录网站A后存在本地的cookie,之后打开了另一个危险网站B,这个网站B使用本地cookie向网站A发起请求(该请求不是用户主动发起,是个恶意请求),网站A误以为是......
  • MySqlException(0x80004005) Reading from the stream has failed 远程主机强迫关闭了
    不同客户端电脑连接服务器数据库,通过navicat管理工具可以正常连上,但是通过程序连接提示MySqlException(0x80004005)Readingfromthestreamhasfailed远程主机强迫关闭了一个现有的连接(注意:部分电脑通过程序也是可以正常连接服务器数据库的)解决方法:服务器重新安装Micr......
  • docker报错:Error response from daemon: driver failed programming external connect
    重启docker-compose时,nginx服务报错。报错信息:Errorresponsefromdaemon:driverfailedprogrammingexternalconnectivityonendpointlikeshop-nginx(f0a809481f5016e6f7ca6e1ed826b0676d5523b15f2954a2d22c03c12a89567d):Bindfor0.0.0.0:80failed:portisalr......
  • mac 使用 brew安装包报错 fatal: not in a git directory,Error: Command failed with
    在mac下使用brew安装包的时候,最后一行会报错:fatal:notinagitdirectoryError:Commandfailedwithexit128:git导致包安装不成功,解决办法:brew-v 绿色框就是提示你需要做的,输入gitconfig--global--addsafe.directory/opt/homebrew/Library/Taps/homeb......