Изменения, внесенные в запись триггером после обновления в БД, не видны в спящем режиме с помощью findOne и findById - PullRequest
0 голосов
/ 10 октября 2019

Я использую в своем проекте Spring boot 1.5.22, Spring data и Hibernate 5.2.18. Когда я сохраняю свой объект Entity, используя Dao с:

platDao.save(plat);

, в базе данных выполняется триггер типа BEFORE INSERT, который вставляет номер документа в поле базы данных. Когда я делаю выбор из таблицы в базе данных с помощью SQL в моем инструменте базы данных, я вижу значение в этом поле. Но когда я получаю эту запись, используя hibernate с методом findOne, я вижу ноль в этом поле:

Platnosc plat = platDao.findOne(platId);

Я пробовал также это:

Platnosc plat = platDao.findById(platId);

Но результат тот же, поле, котороеустановлен триггером - ноль.

Код моего сервиса:

public List<Platnosc> createDocumentForInvoice(Integer fakturaId) {

    AuthUser user = loginMgr.getLoggedUser();

    Platnosc plat = Platnosc.builder()
            // I don't set field platnoscNr here it is null
            .build();

    platDao.save(plat);

    return plat;
}

Код моего контроллера:

public Response createDocumentForInvoice(
        @RequestParam(value = "fakturaId", required = true) Integer fakturaId) {

    List<Platnosc> platList = platMgr.createDocumentForInvoice(fakturaId);

    // after this I can see in database value of field platnoscNr which was inserted by trigger

    String platNr = platList.stream()
            .map(p -> {
                Platnosc plat = platDao.findById(p.getPlatnoscId());     
                return String.format("%s nr %s",
                        platMgr.getRodzajTextForPlatnoscRodzaj(plat.getPlatnoscRodzaj()),
                        plat.getPlatnoscNr());
            })
            .collect(Collectors.joining(", "));

    return Response.ok(platList.size() == 0
            ? "No document was created"
            : "Created documents: " + platNr)
            .build();
}

Ответ:

"Созданные документы: КРЕДИТНАЯ КАРТА № нуля, ПЕРЕДАЧА № нуля, ДРУГАЯ ПЛАТА № нуля "

my DEGUG.log:

    // ....
2019-10-10 17:29:33 - Participating in existing transaction
2019-10-10 17:29:33 - insert into PLATNOSC (BANK_ID, EMPLOYEE_ID, FAKTURA_ID, FAKTURA_ID1, FIRMA_ID, GRUPA_ID, KASA_ID, MELDUNEK_ID, OSOBA_ID, PLATNOSC_DATA, PLATNOSC_DATA_KARTY, PLATNOSC_DEKRET_ID, PLATNOSC_FK_NR, PLATNOSC_FORPLA, PLATNOSC_KOD_SYSTEMU, PLATNOSC_KWOTA, PLATNOSC_NR, PLATNOSC_NUMER_KARTY, PLATNOSC_OPIS, PLATNOSC_PREFIX, PLATNOSC_RODZAJ, PLATNOSC_RODZAJ_KARTY_ID, PLATNOSC_STATUS, PLATNOSC_STWORZ_ZALICZKE, PLATNOSC_USED, PLATNOSC_Z_PLATNOSC_ID, PLATONLINE_ID, POKOJ_ID, RACHOTW_ID, REZERWACJA_ID, WALUTA_ID, ZALICZKA_ID, ZMIANA_ID, PLATNOSC_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2019-10-10 17:29:33 - select platnosc0_.PLATNOSC_ID as PLATNOSC1_90_, platnosc0_.BANK_ID as BANK_ID2_90_, platnosc0_.EMPLOYEE_ID as EMPLOYEE3_90_, platnosc0_.FAKTURA_ID as FAKTURA_4_90_, platnosc0_.FAKTURA_ID1 as FAKTURA_5_90_, platnosc0_.FIRMA_ID as FIRMA_ID6_90_, platnosc0_.GRUPA_ID as GRUPA_ID7_90_, platnosc0_.KASA_ID as KASA_ID8_90_, platnosc0_.MELDUNEK_ID as MELDUNEK9_90_, platnosc0_.OSOBA_ID as OSOBA_I10_90_, platnosc0_.PLATNOSC_DATA as PLATNOS11_90_, platnosc0_.PLATNOSC_DATA_KARTY as PLATNOS12_90_, platnosc0_.PLATNOSC_DEKRET_ID as PLATNOS13_90_, platnosc0_.PLATNOSC_FK_NR as PLATNOS14_90_, platnosc0_.PLATNOSC_FORPLA as PLATNOS15_90_, platnosc0_.PLATNOSC_KOD_SYSTEMU as PLATNOS16_90_, platnosc0_.PLATNOSC_KWOTA as PLATNOS17_90_, platnosc0_.PLATNOSC_NR as PLATNOS18_90_, platnosc0_.PLATNOSC_NUMER_KARTY as PLATNOS19_90_, platnosc0_.PLATNOSC_OPIS as PLATNOS20_90_, platnosc0_.PLATNOSC_PREFIX as PLATNOS21_90_, platnosc0_.PLATNOSC_RODZAJ as PLATNOS22_90_, platnosc0_.PLATNOSC_RODZAJ_KARTY_ID as PLATNOS23_90_, platnosc0_.PLATNOSC_STATUS as PLATNOS24_90_, platnosc0_.PLATNOSC_STWORZ_ZALICZKE as PLATNOS25_90_, platnosc0_.PLATNOSC_USED as PLATNOS26_90_, platnosc0_.PLATNOSC_Z_PLATNOSC_ID as PLATNOS27_90_, platnosc0_.PLATONLINE_ID as PLATONL28_90_, platnosc0_.POKOJ_ID as POKOJ_I29_90_, platnosc0_.RACHOTW_ID as RACHOTW30_90_, platnosc0_.REZERWACJA_ID as REZERWA31_90_, platnosc0_.WALUTA_ID as WALUTA_32_90_, platnosc0_.ZALICZKA_ID as ZALICZK33_90_, platnosc0_.ZMIANA_ID as ZMIANA_34_90_ from PLATNOSC platnosc0_ where platnosc0_.FAKTURA_ID=?
2019-10-10 17:29:33 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:33 - Participating in existing transaction
2019-10-10 17:29:33 - select platnosc0_.PLATNOSC_ID as PLATNOSC1_90_, platnosc0_.BANK_ID as BANK_ID2_90_, platnosc0_.EMPLOYEE_ID as EMPLOYEE3_90_, platnosc0_.FAKTURA_ID as FAKTURA_4_90_, platnosc0_.FAKTURA_ID1 as FAKTURA_5_90_, platnosc0_.FIRMA_ID as FIRMA_ID6_90_, platnosc0_.GRUPA_ID as GRUPA_ID7_90_, platnosc0_.KASA_ID as KASA_ID8_90_, platnosc0_.MELDUNEK_ID as MELDUNEK9_90_, platnosc0_.OSOBA_ID as OSOBA_I10_90_, platnosc0_.PLATNOSC_DATA as PLATNOS11_90_, platnosc0_.PLATNOSC_DATA_KARTY as PLATNOS12_90_, platnosc0_.PLATNOSC_DEKRET_ID as PLATNOS13_90_, platnosc0_.PLATNOSC_FK_NR as PLATNOS14_90_, platnosc0_.PLATNOSC_FORPLA as PLATNOS15_90_, platnosc0_.PLATNOSC_KOD_SYSTEMU as PLATNOS16_90_, platnosc0_.PLATNOSC_KWOTA as PLATNOS17_90_, platnosc0_.PLATNOSC_NR as PLATNOS18_90_, platnosc0_.PLATNOSC_NUMER_KARTY as PLATNOS19_90_, platnosc0_.PLATNOSC_OPIS as PLATNOS20_90_, platnosc0_.PLATNOSC_PREFIX as PLATNOS21_90_, platnosc0_.PLATNOSC_RODZAJ as PLATNOS22_90_, platnosc0_.PLATNOSC_RODZAJ_KARTY_ID as PLATNOS23_90_, platnosc0_.PLATNOSC_STATUS as PLATNOS24_90_, platnosc0_.PLATNOSC_STWORZ_ZALICZKE as PLATNOS25_90_, platnosc0_.PLATNOSC_USED as PLATNOS26_90_, platnosc0_.PLATNOSC_Z_PLATNOSC_ID as PLATNOS27_90_, platnosc0_.PLATONLINE_ID as PLATONL28_90_, platnosc0_.POKOJ_ID as POKOJ_I29_90_, platnosc0_.RACHOTW_ID as RACHOTW30_90_, platnosc0_.REZERWACJA_ID as REZERWA31_90_, platnosc0_.WALUTA_ID as WALUTA_32_90_, platnosc0_.ZALICZKA_ID as ZALICZK33_90_, platnosc0_.ZMIANA_ID as ZMIANA_34_90_ from PLATNOSC platnosc0_ where platnosc0_.FAKTURA_ID=?
2019-10-10 17:29:33 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:33 - Participating in existing transaction
2019-10-10 17:29:33 - select platnosc0_.PLATNOSC_ID as PLATNOSC1_90_, platnosc0_.BANK_ID as BANK_ID2_90_, platnosc0_.EMPLOYEE_ID as EMPLOYEE3_90_, platnosc0_.FAKTURA_ID as FAKTURA_4_90_, platnosc0_.FAKTURA_ID1 as FAKTURA_5_90_, platnosc0_.FIRMA_ID as FIRMA_ID6_90_, platnosc0_.GRUPA_ID as GRUPA_ID7_90_, platnosc0_.KASA_ID as KASA_ID8_90_, platnosc0_.MELDUNEK_ID as MELDUNEK9_90_, platnosc0_.OSOBA_ID as OSOBA_I10_90_, platnosc0_.PLATNOSC_DATA as PLATNOS11_90_, platnosc0_.PLATNOSC_DATA_KARTY as PLATNOS12_90_, platnosc0_.PLATNOSC_DEKRET_ID as PLATNOS13_90_, platnosc0_.PLATNOSC_FK_NR as PLATNOS14_90_, platnosc0_.PLATNOSC_FORPLA as PLATNOS15_90_, platnosc0_.PLATNOSC_KOD_SYSTEMU as PLATNOS16_90_, platnosc0_.PLATNOSC_KWOTA as PLATNOS17_90_, platnosc0_.PLATNOSC_NR as PLATNOS18_90_, platnosc0_.PLATNOSC_NUMER_KARTY as PLATNOS19_90_, platnosc0_.PLATNOSC_OPIS as PLATNOS20_90_, platnosc0_.PLATNOSC_PREFIX as PLATNOS21_90_, platnosc0_.PLATNOSC_RODZAJ as PLATNOS22_90_, platnosc0_.PLATNOSC_RODZAJ_KARTY_ID as PLATNOS23_90_, platnosc0_.PLATNOSC_STATUS as PLATNOS24_90_, platnosc0_.PLATNOSC_STWORZ_ZALICZKE as PLATNOS25_90_, platnosc0_.PLATNOSC_USED as PLATNOS26_90_, platnosc0_.PLATNOSC_Z_PLATNOSC_ID as PLATNOS27_90_, platnosc0_.PLATONLINE_ID as PLATONL28_90_, platnosc0_.POKOJ_ID as POKOJ_I29_90_, platnosc0_.RACHOTW_ID as RACHOTW30_90_, platnosc0_.REZERWACJA_ID as REZERWA31_90_, platnosc0_.WALUTA_ID as WALUTA_32_90_, platnosc0_.ZALICZKA_ID as ZALICZK33_90_, platnosc0_.ZMIANA_ID as ZMIANA_34_90_ from PLATNOSC platnosc0_ where platnosc0_.FAKTURA_ID1=?
2019-10-10 17:29:33 - Initiating transaction commit
2019-10-10 17:29:33 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-10-10 17:29:33 - Not closing pre-bound JPA EntityManager after transaction
    // here is findById() method called
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2019-10-10 17:29:46 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@6f808572]
2019-10-10 17:29:46 - select platnosc0_.PLATNOSC_ID as PLATNOSC1_90_, platnosc0_.BANK_ID as BANK_ID2_90_, platnosc0_.EMPLOYEE_ID as EMPLOYEE3_90_, platnosc0_.FAKTURA_ID as FAKTURA_4_90_, platnosc0_.FAKTURA_ID1 as FAKTURA_5_90_, platnosc0_.FIRMA_ID as FIRMA_ID6_90_, platnosc0_.GRUPA_ID as GRUPA_ID7_90_, platnosc0_.KASA_ID as KASA_ID8_90_, platnosc0_.MELDUNEK_ID as MELDUNEK9_90_, platnosc0_.OSOBA_ID as OSOBA_I10_90_, platnosc0_.PLATNOSC_DATA as PLATNOS11_90_, platnosc0_.PLATNOSC_DATA_KARTY as PLATNOS12_90_, platnosc0_.PLATNOSC_DEKRET_ID as PLATNOS13_90_, platnosc0_.PLATNOSC_FK_NR as PLATNOS14_90_, platnosc0_.PLATNOSC_FORPLA as PLATNOS15_90_, platnosc0_.PLATNOSC_KOD_SYSTEMU as PLATNOS16_90_, platnosc0_.PLATNOSC_KWOTA as PLATNOS17_90_, platnosc0_.PLATNOSC_NR as PLATNOS18_90_, platnosc0_.PLATNOSC_NUMER_KARTY as PLATNOS19_90_, platnosc0_.PLATNOSC_OPIS as PLATNOS20_90_, platnosc0_.PLATNOSC_PREFIX as PLATNOS21_90_, platnosc0_.PLATNOSC_RODZAJ as PLATNOS22_90_, platnosc0_.PLATNOSC_RODZAJ_KARTY_ID as PLATNOS23_90_, platnosc0_.PLATNOSC_STATUS as PLATNOS24_90_, platnosc0_.PLATNOSC_STWORZ_ZALICZKE as PLATNOS25_90_, platnosc0_.PLATNOSC_USED as PLATNOS26_90_, platnosc0_.PLATNOSC_Z_PLATNOSC_ID as PLATNOS27_90_, platnosc0_.PLATONLINE_ID as PLATONL28_90_, platnosc0_.POKOJ_ID as POKOJ_I29_90_, platnosc0_.RACHOTW_ID as RACHOTW30_90_, platnosc0_.REZERWACJA_ID as REZERWA31_90_, platnosc0_.WALUTA_ID as WALUTA_32_90_, platnosc0_.ZALICZKA_ID as ZALICZK33_90_, platnosc0_.ZMIANA_ID as ZMIANA_34_90_ from PLATNOSC platnosc0_ where platnosc0_.PLATNOSC_ID=?
2019-10-10 17:29:46 - Initiating transaction commit
2019-10-10 17:29:46 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-10-10 17:29:46 - Not closing pre-bound JPA EntityManager after transaction
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Creating new transaction with name [ekoncept.service.PlatnoscServiceImpl.getRodzajTextForPlatnoscRodzaj]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2019-10-10 17:29:46 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@5cc07ca4]
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#101]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Participating in existing transaction
2019-10-10 17:29:46 - select stale0_.STALE_ID as STALE_ID1_134_0_, stale0_.STALE_CENTRUM_PRZYCH as STALE_CE2_134_0_, stale0_.STALE_KOD_SYSTEMU as STALE_KO3_134_0_, stale0_.STALE_KONTOKSIEGOWE_ID as STALE_KO4_134_0_, stale0_.STALE_NAZWA as STALE_NA5_134_0_, stale0_.STALE_RODZAJ_ID as STALE_RO6_134_0_, stale0_.STALE_WARTOSC as STALE_WA7_134_0_, stale0_.STALE_WARTOSC2 as STALE_WA8_134_0_, stale0_.STALE_WARTOSC3 as STALE_WA9_134_0_, stale0_.STALE_WARTOSC_EN as STALE_W10_134_0_, stale0_.STALE_WARTOSC_FLOAT as STALE_W11_134_0_, stale0_.STALE_WARTOSC_INT as STALE_W12_134_0_, stale0_.STALE_WARTOSC_INT2 as STALE_W13_134_0_, stale0_.STALE_WIDOCZNOSC as STALE_W14_134_0_ from STALE stale0_ where stale0_.STALE_ID=?
2019-10-10 17:29:46 - Initiating transaction commit
2019-10-10 17:29:46 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-10-10 17:29:46 - Not closing pre-bound JPA EntityManager after transaction
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2019-10-10 17:29:46 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@2c0c9b9d]
2019-10-10 17:29:46 - select platnosc0_.PLATNOSC_ID as PLATNOSC1_90_, platnosc0_.BANK_ID as BANK_ID2_90_, platnosc0_.EMPLOYEE_ID as EMPLOYEE3_90_, platnosc0_.FAKTURA_ID as FAKTURA_4_90_, platnosc0_.FAKTURA_ID1 as FAKTURA_5_90_, platnosc0_.FIRMA_ID as FIRMA_ID6_90_, platnosc0_.GRUPA_ID as GRUPA_ID7_90_, platnosc0_.KASA_ID as KASA_ID8_90_, platnosc0_.MELDUNEK_ID as MELDUNEK9_90_, platnosc0_.OSOBA_ID as OSOBA_I10_90_, platnosc0_.PLATNOSC_DATA as PLATNOS11_90_, platnosc0_.PLATNOSC_DATA_KARTY as PLATNOS12_90_, platnosc0_.PLATNOSC_DEKRET_ID as PLATNOS13_90_, platnosc0_.PLATNOSC_FK_NR as PLATNOS14_90_, platnosc0_.PLATNOSC_FORPLA as PLATNOS15_90_, platnosc0_.PLATNOSC_KOD_SYSTEMU as PLATNOS16_90_, platnosc0_.PLATNOSC_KWOTA as PLATNOS17_90_, platnosc0_.PLATNOSC_NR as PLATNOS18_90_, platnosc0_.PLATNOSC_NUMER_KARTY as PLATNOS19_90_, platnosc0_.PLATNOSC_OPIS as PLATNOS20_90_, platnosc0_.PLATNOSC_PREFIX as PLATNOS21_90_, platnosc0_.PLATNOSC_RODZAJ as PLATNOS22_90_, platnosc0_.PLATNOSC_RODZAJ_KARTY_ID as PLATNOS23_90_, platnosc0_.PLATNOSC_STATUS as PLATNOS24_90_, platnosc0_.PLATNOSC_STWORZ_ZALICZKE as PLATNOS25_90_, platnosc0_.PLATNOSC_USED as PLATNOS26_90_, platnosc0_.PLATNOSC_Z_PLATNOSC_ID as PLATNOS27_90_, platnosc0_.PLATONLINE_ID as PLATONL28_90_, platnosc0_.POKOJ_ID as POKOJ_I29_90_, platnosc0_.RACHOTW_ID as RACHOTW30_90_, platnosc0_.REZERWACJA_ID as REZERWA31_90_, platnosc0_.WALUTA_ID as WALUTA_32_90_, platnosc0_.ZALICZKA_ID as ZALICZK33_90_, platnosc0_.ZMIANA_ID as ZMIANA_34_90_ from PLATNOSC platnosc0_ where platnosc0_.PLATNOSC_ID=?
2019-10-10 17:29:46 - Initiating transaction commit
2019-10-10 17:29:46 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-10-10 17:29:46 - Not closing pre-bound JPA EntityManager after transaction
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Creating new transaction with name [ekoncept.service.PlatnoscServiceImpl.getRodzajTextForPlatnoscRodzaj]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2019-10-10 17:29:46 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7a494edf]
2019-10-10 17:29:46 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-10-10 17:29:46 - Participating in existing transaction
2019-10-10 17:29:46 - select stale0_.STALE_ID as STALE_ID1_134_0_, stale0_.STALE_CENTRUM_PRZYCH as STALE_CE2_134_0_, stale0_.STALE_KOD_SYSTEMU as STALE_KO3_134_0_, stale0_.STALE_KONTOKSIEGOWE_ID as STALE_KO4_134_0_, stale0_.STALE_NAZWA as STALE_NA5_134_0_, stale0_.STALE_RODZAJ_ID as STALE_RO6_134_0_, stale0_.STALE_WARTOSC as STALE_WA7_134_0_, stale0_.STALE_WARTOSC2 as STALE_WA8_134_0_, stale0_.STALE_WARTOSC3 as STALE_WA9_134_0_, stale0_.STALE_WARTOSC_EN as STALE_W10_134_0_, stale0_.STALE_WARTOSC_FLOAT as STALE_W11_134_0_, stale0_.STALE_WARTOSC_INT as STALE_W12_134_0_, stale0_.STALE_WARTOSC_INT2 as STALE_W13_134_0_, stale0_.STALE_WIDOCZNOSC as STALE_W14_134_0_ from STALE stale0_ where stale0_.STALE_ID=?
2019-10-10 17:29:46 - Initiating transaction commit
2019-10-10 17:29:46 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.entity.Stale#402], EntityKey[ekoncept.entity.Stale#101], EntityKey[ekoncept.entity.Platnosc#59905], EntityKey[ekoncept.entity.Platnosc#59858], EntityKey[ekoncept.entity.Faktura#141935], EntityKey[ekoncept.entity.Platnosc#59903], EntityKey[ekoncept.entity.Platnosc#59904], EntityKey[ekoncept.entity.Stale#401]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-10-10 17:29:46 - Not closing pre-bound JPA EntityManager after transaction

Почему Hibernate не видит значение поля platnoscNr ??

Ответы [ 2 ]

1 голос
/ 10 октября 2019

Обновить сущность после сохранения. См. Ссылку для обновления

0 голосов
/ 11 октября 2019

Чтобы увидеть изменения, сделанные триггером, я добавил две строки кода в свой сервис после platDao.save (plat):

  1. entityManager.flush ();

Операция EntityManager.flush () может использоваться для записи всех изменений в базу данных до совершения транзакции. Flush () не выполняет фактическую фиксацию.

entityManager.refresh (plat);

Операция EntityManager.refresh () используется для обновления состояния объекта из базы данных. Обновление можно использовать для отмены изменений, или, если ваш поставщик JPA поддерживает кэширование, его можно использовать для обновления устаревших кэшированных данных. Иногда желательно, чтобы операция Query or find обновляла результаты.

Теперь мой код выглядит так:

public List<Platnosc> createDocumentForInvoice(Integer fakturaId) {

   AuthUser user = loginMgr.getLoggedUser();

   Platnosc plat = Platnosc.builder()
        // I don't set field platnoscNr here it is null
        .build();

    platDao.save(plat);
    entityManager.flush();
    entityManager.refresh(plat);

    return plat;
}
...