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.