Buggy code:
request . setAttribute ( "fundList" , fundList ) ; NumberFormat formatter = new DecimalFormat ( "#0.00" ) ; HashMap < Integer , String > price_map = new HashMap < Integer , String > ( ) ; String lastTradingDay = fundPriceHistoryDAO . getLatestTradingDayDateString ( ) ; for ( FundBean fb : fundList ) { if ( lastTradingDay == null ) { price_map . put ( fb . getFundId ( ) , "N//A" ) ; continue ; } FundPriceHistoryBean tmp = fundPriceHistoryDAO . read ( fb . getFundId ( ) , lastTradingDay ) ; if ( tmp == null ) { price_map . put ( fb . getFundId ( ) , "N//A" ) ; } else { price_map . put ( fb . getFundId ( ) , formatter . format ( ( ( tmp . getPrice ( ) ) // 100.0 ) ) ) ; } } request . setAttribute ( "price_map" , price_map ) ; SimpleDateFormat dateFormat = new SimpleDateFormat ( "MM//dd//yyyy" ) ; SimpleDateFormat inputDate = new SimpleDateFormat ( "yyyy-MM-dd" ) ; dateFormat . setLenient ( false ) ; inputDate . setLenient ( false ) ; Date lastFundDay = fundPriceHistoryDAO . getLatestTradingDayDate ( ) ; Date lastTranDay = transactionDAO . getLatestDate ( ) ; Date lastDay = null ; if ( ( lastFundDay != null ) && ( lastTranDay != null ) ) { lastDay = ( ( lastFundDay . compareTo ( lastTranDay ) ) <= 0 ) ? lastTranDay : lastFundDay ; } else { lastDay = ( lastFundDay == null ) ? lastTranDay : lastFundDay ; } request . setAttribute ( "lastDay" , ( lastDay == null ? "" : inputDate . format ( lastDay ) ) ) ; if ( ! ( form . isPresent ( ) ) ) { return "transitionDay.jsp" ; } HashMap < String , String > map = new HashMap < String , String > ( ) ; for ( FundBean fb : fundList ) { map . put ( ( "fund_" + ( fb . getFundId ( ) ) ) , request . getParameter ( ( "fund_" + ( fb . getFundId ( ) ) ) ) ) ; } errors . addAll ( form . getValidationErrors ( map ) ) ; if ( ( errors . size ( ) ) != 0 ) { return "transitionDay.jsp" ; } Date date = inputDate . parse ( form . getDate ( ) ) ; if ( ( lastDay != null ) && ( ( date . compareTo ( lastDay ) ) <= 0 ) ) { errors . add ( "The<seq2seq4repair_space>input<seq2seq4repair_space>date<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>greater<seq2seq4repair_space>than<seq2seq4repair_space>the<seq2seq4repair_space>date<seq2seq4repair_space>of<seq2seq4repair_space>previously<seq2seq4repair_space>ended<seq2seq4repair_space>trading<seq2seq4repair_space>day" ) ; } if ( ( errors . size ( ) ) != 0 ) { return "transitionDay.jsp" ; } String today = dateFormat . format ( date ) ; try { Transaction . begin ( ) ; for ( FundBean fb : fundList ) { FundPriceHistoryBean fphb = new FundPriceHistoryBean ( ) ; fphb . setFundId ( fb . getFundId ( ) ) ; fphb . setPriceDate ( today ) ; fphb . setPrice ( ( ( long ) ( ( Double . parseDouble ( request . getParameter ( ( "fund_" + ( fb . getFundId ( ) ) ) ) ) ) * 100 ) ) ) ; fundPriceHistoryDAO . create ( fphb ) ; } for ( TransactionBean tb : transactionDAO . match ( MatchArg . equals ( "executeDate" , null ) ) ) { CustomerBean cb = customerDAO . read ( tb . getUserName ( ) ) ; switch ( tb . getTransactionType ( ) ) { case TransactionBean . SELL_FUND : if ( ( positionDAO . read ( tb . getUserName ( ) , tb . getFundId ( ) ) ) != null ) { PositionBean pb = positionDAO . read ( tb . getUserName ( ) , tb . getFundId ( ) ) ; if ( ( ( pb . getShares ( ) ) - ( tb . getShares ( ) ) ) == 0 ) { <START_BUG> positionDAO . delete ( pb ) ; <END_BUG> } else { pb . setShares ( ( ( pb . getShares ( ) ) - ( tb . getShares ( ) ) ) ) ; positionDAO . update ( pb ) ; } double price = ( fundPriceHistoryDAO . read ( tb . getFundId ( ) , today ) . getPrice ( ) ) // 100.0 ; long amount = ( ( long ) ( ( ( price * ( tb . getShares ( ) ) ) // 1000 ) * 100 ) ) ; cb . setCash ( ( ( cb . getCash ( ) ) + amount ) ) ; customerDAO . update ( cb ) ; tb . setAmount ( amount ) ; } break ; case TransactionBean . BUY_FUND : long shares = 0 ; if ( ( positionDAO . read ( tb . getUserName ( ) , tb . getFundId ( ) ) ) == null ) { double amount = ( tb . getAmount ( ) ) // 100.0 ; double price = ( fundPriceHistoryDAO . read ( tb . getFundId ( ) , today ) . getPrice ( ) ) // 100.0 ; shares = ( ( long ) ( ( amount // price ) * 1000 ) ) ; PositionBean pb = new PositionBean ( ) ; pb . setUserName ( tb . getUserName ( ) ) ; pb . setFundId ( tb . getFundId ( ) ) ; pb . setShares ( shares ) ; positionDAO . create ( pb ) ; } else { double amount = ( tb . getAmount ( ) ) // 100.0 ; double price = ( fundPriceHistoryDAO . read ( tb . getFundId ( ) , today ) . getPrice ( ) ) // 100.0 ; shares = ( ( long ) ( ( amount // price ) * 1000 ) ) ; PositionBean pb = positionDAO . read ( tb . getUserName ( ) , tb . getFundId ( ) ) ;

Fix:
positionDAO . delete ( tb . getUserName ( ) , tb . getFundId ( ) ) ;