2016-07-25 13 views
0

オブジェクト配列を返すメソッドがあります。 catalogVersion変数は、OECATVERエンティティに関連付けられています。何らかの理由で私が理解できない、このObject []を返すと、コードはOECATVERの更新クエリを呼び出します。私はそれを引き起こす何も見ることができず、このオブジェクトが返された直後に起こるように見えます。このメソッドで実行されるのは、findOne(id)だけです。それは更新を引き起こすべきではないでしょうか?Hibernate/Spring JPA findOne()呼び出し更新コマンド

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) { 
     // We have the version, make sure it's still valid... 
     // If it's not dead... 
     if (!isCatalogDead(catalogVersion)) { 
      // If it's active and not expired, add to the map. 
      if (isCatalogActive(catalogVersion, itemBusinessUnit)) { 
       if (!isCatalogExpired(catalogVersion)) { 
        // Do 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; 
} 

これは、このメソッドを実行するときに表示されるログです。

Hibernate: select catalogpre0_.BUSUNTNBR as BUSUNTNB1_41_0_, catalogpre0_.CATPFX as CATPFX2_41_0_, catalogpre0_.lstupdjob as lstupdjo3_41_0_, catalogpre0_.lstupdnbr as lstupdnb4_41_0_, catalogpre0_.lstupdpgm as lstupdpg5_41_0_, catalogpre0_.lstupdtsp as lstupdts6_41_0_, catalogpre0_.lstupdusr as lstupdus7_41_0_, catalogpre0_.CATNBR as CATNBR8_41_0_, catalogpre0_.CATVER as CATVER9_41_0_ from OECATPFX catalogpre0_ where catalogpre0_.BUSUNTNBR=? and catalogpre0_.CATPFX=? 
Hibernate: select catalogver0_.BUSUNTNBR as BUSUNTNB1_43_0_, catalogver0_.CATNBR as CATNBR2_43_0_, catalogver0_.CATVER as CATVER3_43_0_, catalogver0_.lstupdjob as lstupdjo4_43_0_, catalogver0_.lstupdnbr as lstupdnb5_43_0_, catalogver0_.lstupdpgm as lstupdpg6_43_0_, catalogver0_.lstupdtsp as lstupdts7_43_0_, catalogver0_.lstupdusr as lstupdus8_43_0_, catalogver0_.CATVERDSC as CATVERDS9_43_0_, catalogver0_.CURCATPCG as CURCATP10_43_0_, catalogver0_.EFFDAT as EFFDAT11_43_0_, catalogver0_.EXPDAT as EXPDAT12_43_0_, catalogver0_.PSDSALFLG as PSDSALF13_43_0_ from OECATVER catalogver0_ where catalogver0_.BUSUNTNBR=? and catalogver0_.CATNBR=? and catalogver0_.CATVER=? 
Hibernate: select catalog0_.BUSUNTNBR as BUSUNTNB1_40_0_, catalog0_.CATNBR as CATNBR2_40_0_, catalog0_.lstupdjob as lstupdjo3_40_0_, catalog0_.lstupdnbr as lstupdnb4_40_0_, catalog0_.lstupdpgm as lstupdpg5_40_0_, catalog0_.lstupdtsp as lstupdts6_40_0_, catalog0_.lstupdusr as lstupdus7_40_0_, catalog0_.CATEOLDAT as CATEOLDA8_40_0_, catalog0_.CATNAM as CATNAM9_40_0_, catalog0_.CATTHMCLF as CATTHMC10_40_0_, catalog0_.CATTYPCLF as CATTYPC11_40_0_ from OECATMST catalog0_ where catalog0_.BUSUNTNBR=? and catalog0_.CATNBR=? 
Hibernate: select orderentry0_.BUSUNTNBR as BUSUNTNB1_6_0_, orderentry0_.lstupdjob as lstupdjo2_6_0_, orderentry0_.lstupdnbr as lstupdnb3_6_0_, orderentry0_.lstupdpgm as lstupdpg4_6_0_, orderentry0_.lstupdtsp as lstupdts5_6_0_, orderentry0_.lstupdusr as lstupdus6_6_0_, orderentry0_.AREMLPMP as AREMLPMP7_6_0_, orderentry0_.ALWNTLACT as ALWNTLAC8_6_0_, orderentry0_.ATOASNCGY as ATOASNCG9_6_0_, orderentry0_.AVLJOBSFY as AVLJOBS10_6_0_, orderentry0_.CASQTYLMT as CASQTYL11_6_0_, orderentry0_.COPITMFLG as COPITMF12_6_0_, orderentry0_.CREPSPCUS as CREPSPC13_6_0_, orderentry0_.VRLCATNBR as VRLCATN14_6_0_, orderentry0_.VRLCATPFX as VRLCATP15_6_0_, orderentry0_.VRLCATVER as VRLCATV16_6_0_, orderentry0_.VRLKEYCOD as VRLKEYC17_6_0_, orderentry0_.DFTQTEDAY as DFTQTED18_6_0_, orderentry0_.DSPOFRPRV as DSPOFRP19_6_0_, orderentry0_.DUPORD as DUPORD20_6_0_, orderentry0_.EMLPMPFLG as EMLPMPF21_6_0_, orderentry0_.EMPKEYCOD as EMPKEYC22_6_0_, orderentry0_.HGHPRCCHK as HGHPRCC23_6_0_, orderentry0_.HGHQTYCHK as HGHQTYC24_6_0_, orderentry0_.IPRCNFAMT as IPRCNFA25_6_0_, orderentry0_."Jobber Safety Threshold" as Jobber26_6_0_, orderentry0_.MAXQTEDAY as MAXQTED27_6_0_, orderentry0_.PFXRQDFLG as PFXRQDF28_6_0_, orderentry0_.PRCOVRCHK as PRCOVRC29_6_0_, orderentry0_.PRCGRCPED as PRCGRCP30_6_0_, orderentry0_.ORDRSNCLF as ORDRSNC31_6_0_, orderentry0_.RQROPBFLG as RQROPBF32_6_0_, orderentry0_.SPLTABRQD as SPLTABR33_6_0_, orderentry0_.USEKEYCGY as USEKEYC34_6_0_, orderentry0_.WGTLMT as WGTLMT35_6_0_ from COBRLORD orderentry0_ where orderentry0_.BUSUNTNBR=? 
Hibernate: update OECATVER set lstupdjob=?, lstupdnbr=?, lstupdpgm=?, lstupdtsp=?, lstupdusr=?, CATVERDSC=?, CURCATPCG=?, EFFDAT=?, EXPDAT=?, PSDSALFLG=? where BUSUNTNBR=? and CATNBR=? and CATVER=? 

更新:

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 to see if the catalog is 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; 
    } 

} 
+0

すごい...内部のものです:isCatalogDead。 isCatalogActive; isCatalogExpired?トランザクション内であれば、.save(エンティティ)を呼び出しているかどうかにかかわらず、変更はdbにも保存されます。 – Sarief

+0

ちょうどあなたが知っている、あなたはこれをリファクタリングする必要があります...また、命名... – Sarief

答えて

0

私は問題を決定することができました。問題はisCatalogActive()メソッドにありました。下記を参照してください。 fromDate変数を更新すると、catalogVersionの日付も更新されていました。 fromDateの新しいCalendarオブジェクトを作成し、その時間をcatalogVersion.getEffectiveDate()と同じにするように変更しました。その方法でfromDateと作業しました。

古い方法

public boolean isCatalogActive(CatalogVersion catalogVersion, int itemBusinessUnit) { 
    Calendar today = Calendar.getInstance(); 
    // Check to see if the catalog is 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 to see if the catalog is 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; 
    } 
} 
関連する問題