java - Hibernate/Spring JPA findOne() calling update command -
i have method return object array. catalogversion variable tied oecatver entity. reason cannot understand, when return object[], code calls update query on oecatver. can't see cause , appears happen after object returned. queries see performed in method findone(id). shouldn't cause update, should it?
public object[] getprefixcatalogversion(string itemprefix, int itembusinessunit) { catalogversion catalogversion = null; string prefixreplacementreason = null; object[] versionandreason = new object[2]; catalogprefixkey prefixkey = new catalogprefixkey(); prefixkey.setbusinessunit(itembusinessunit); prefixkey.setcatalogprefix(itemprefix); catalogprefix catprefix = catalogprefixrepository.findone(prefixkey); catalogversionkey versionkey = new catalogversionkey(); versionkey.setbusinessunit(catprefix.getkey().getbusinessunit()); versionkey.setcatalognumber(catprefix.getcatalognumber()); versionkey.setcatalogversion(catprefix.getcatalogversion()); catalogversion = catalogversionrepository.findone(versionkey); if (catalogversion != null) { // have version, make sure it's still valid... // if it's not dead... if (!iscatalogdead(catalogversion)) { // if it's active , not expired, add map. if (iscatalogactive(catalogversion, itembusinessunit)) { if (!iscatalogexpired(catalogversion)) { // nothing } else { prefixreplacementreason = commonconstants.prefix_replacement_reason_expired; } } else { prefixreplacementreason = commonconstants.prefix_replacement_reason_not_active; } } else { prefixreplacementreason = commonconstants.prefix_replacement_reason_end_life; } } else { prefixreplacementreason = commonconstants.prefix_replacement_reason_invalid; } versionandreason[0] = catalogversion; versionandreason[1] = prefixreplacementreason; return versionandreason; }
these logs see when running method.
hibernate: select catalogpre0_.busuntnbr busuntnb1_41_0_, catalogpre0_.catpfx catpfx2_41_0_, catalogpre0_.lstupdjob lstupdjo3_41_0_, catalogpre0_.lstupdnbr lstupdnb4_41_0_, catalogpre0_.lstupdpgm lstupdpg5_41_0_, catalogpre0_.lstupdtsp lstupdts6_41_0_, catalogpre0_.lstupdusr lstupdus7_41_0_, catalogpre0_.catnbr catnbr8_41_0_, catalogpre0_.catver catver9_41_0_ oecatpfx catalogpre0_ catalogpre0_.busuntnbr=? , catalogpre0_.catpfx=? hibernate: select catalogver0_.busuntnbr busuntnb1_43_0_, catalogver0_.catnbr catnbr2_43_0_, catalogver0_.catver catver3_43_0_, catalogver0_.lstupdjob lstupdjo4_43_0_, catalogver0_.lstupdnbr lstupdnb5_43_0_, catalogver0_.lstupdpgm lstupdpg6_43_0_, catalogver0_.lstupdtsp lstupdts7_43_0_, catalogver0_.lstupdusr lstupdus8_43_0_, catalogver0_.catverdsc catverds9_43_0_, catalogver0_.curcatpcg curcatp10_43_0_, catalogver0_.effdat effdat11_43_0_, catalogver0_.expdat expdat12_43_0_, catalogver0_.psdsalflg psdsalf13_43_0_ oecatver catalogver0_ catalogver0_.busuntnbr=? , catalogver0_.catnbr=? , catalogver0_.catver=? hibernate: select catalog0_.busuntnbr busuntnb1_40_0_, catalog0_.catnbr catnbr2_40_0_, catalog0_.lstupdjob lstupdjo3_40_0_, catalog0_.lstupdnbr lstupdnb4_40_0_, catalog0_.lstupdpgm lstupdpg5_40_0_, catalog0_.lstupdtsp lstupdts6_40_0_, catalog0_.lstupdusr lstupdus7_40_0_, catalog0_.cateoldat cateolda8_40_0_, catalog0_.catnam catnam9_40_0_, catalog0_.catthmclf catthmc10_40_0_, catalog0_.cattypclf cattypc11_40_0_ oecatmst catalog0_ catalog0_.busuntnbr=? , catalog0_.catnbr=? hibernate: select orderentry0_.busuntnbr busuntnb1_6_0_, orderentry0_.lstupdjob lstupdjo2_6_0_, orderentry0_.lstupdnbr lstupdnb3_6_0_, orderentry0_.lstupdpgm lstupdpg4_6_0_, orderentry0_.lstupdtsp lstupdts5_6_0_, orderentry0_.lstupdusr lstupdus6_6_0_, orderentry0_.aremlpmp aremlpmp7_6_0_, orderentry0_.alwntlact alwntlac8_6_0_, orderentry0_.atoasncgy atoasncg9_6_0_, orderentry0_.avljobsfy avljobs10_6_0_, orderentry0_.casqtylmt casqtyl11_6_0_, orderentry0_.copitmflg copitmf12_6_0_, orderentry0_.crepspcus crepspc13_6_0_, orderentry0_.vrlcatnbr vrlcatn14_6_0_, orderentry0_.vrlcatpfx vrlcatp15_6_0_, orderentry0_.vrlcatver vrlcatv16_6_0_, orderentry0_.vrlkeycod vrlkeyc17_6_0_, orderentry0_.dftqteday dftqted18_6_0_, orderentry0_.dspofrprv dspofrp19_6_0_, orderentry0_.dupord dupord20_6_0_, orderentry0_.emlpmpflg emlpmpf21_6_0_, orderentry0_.empkeycod empkeyc22_6_0_, orderentry0_.hghprcchk hghprcc23_6_0_, orderentry0_.hghqtychk hghqtyc24_6_0_, orderentry0_.iprcnfamt iprcnfa25_6_0_, orderentry0_."jobber safety threshold" jobber26_6_0_, orderentry0_.maxqteday maxqted27_6_0_, orderentry0_.pfxrqdflg pfxrqdf28_6_0_, orderentry0_.prcovrchk prcovrc29_6_0_, orderentry0_.prcgrcped prcgrcp30_6_0_, orderentry0_.ordrsnclf ordrsnc31_6_0_, orderentry0_.rqropbflg rqropbf32_6_0_, orderentry0_.spltabrqd spltabr33_6_0_, orderentry0_.usekeycgy usekeyc34_6_0_, orderentry0_.wgtlmt wgtlmt35_6_0_ cobrlord orderentry0_ orderentry0_.busuntnbr=? hibernate: update oecatver set lstupdjob=?, lstupdnbr=?, lstupdpgm=?, lstupdtsp=?, lstupdusr=?, catverdsc=?, curcatpcg=?, effdat=?, expdat=?, psdsalflg=? busuntnbr=? , catnbr=? , catver=?
update:
public boolean iscatalogdead(catalogversion catalogversion) { calendar today = calendar.getinstance(); catalogkey key = new catalogkey(); key.setbusinessunit(catalogversion.getkey().getbusinessunit()); key.setcatalognumber(catalogversion.getkey().getcatalognumber()); catalog catalog = catalogrepository.findone(key); if (catalog != null) { calendar endoflifedate = catalog.getendoflifedate(); if (today.after(endoflifedate)) { return true; } else { return false; } } else { return false; } } public boolean iscatalogactive(catalogversion catalogversion, int itembusinessunit) { calendar today = calendar.getinstance(); // check see if catalog still available calendar fromdate = catalogversion.geteffectivedate(); int graceperioddays = companyservice.getpricinggraceperioddays(itembusinessunit); fromdate.add(calendar.day_of_year, graceperioddays * -1); if (today.before(fromdate)) { return false; } else { return true; } } public boolean iscatalogexpired(catalogversion catalogversion) { calendar today = calendar.getinstance(); calendar todate = catalogversion.getexpirationdate(); if (today.after(todate)) { return true; } else { return false; } }
i able determine issue. issue in iscatalogactive() method, see below. when updating fromdate variable, updating date in catalogversion well. changed making new calendar object fromdate , setting time same catalogversion.geteffectivedate(); , worked fromdate way.
old way
public boolean iscatalogactive(catalogversion catalogversion, int itembusinessunit) { calendar today = calendar.getinstance(); // check see if catalog still available calendar fromdate = catalogversion.geteffectivedate(); int graceperioddays = companyservice.getpricinggraceperioddays(itembusinessunit); fromdate.add(calendar.day_of_year, graceperioddays * -1); if (today.before(fromdate)) { return false; } else { return true; } }
new way
public boolean iscatalogactive(catalogversion catalogversion, int itembusinessunit) { calendar today = calendar.getinstance(); // check see if catalog still available calendar fromdate = calendar.getinstance(); fromdate.settime(catalogversion.geteffectivedate().gettime()); int graceperioddays = companyservice.getpricinggraceperioddays(itembusinessunit); fromdate.add(calendar.day_of_year, graceperioddays * -1); if (today.before(fromdate)) { return false; } else { return true; } }
Comments
Post a Comment