JPA does not update a column though Hibernate logs shows an update

I have an async Listener that reads data from a database, parses a file and calls an external service.

The listener is Transactional, as it needs to read from a database.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Async
@EventListener
@Transactional
public void handleUploadedFile(DocumentDto dto) {
final var docEvent = cService.findEvent(documentDto);
final var document = dRepository.findById(dto.getId()).orElseThrow();
cService.saveUploadedDate(docEvent, document);
final var data = cService.saveData(docEvent, document);
extService.execute(data.getId(), docEvent.getId());
}
</code>
<code>@Async @EventListener @Transactional public void handleUploadedFile(DocumentDto dto) { final var docEvent = cService.findEvent(documentDto); final var document = dRepository.findById(dto.getId()).orElseThrow(); cService.saveUploadedDate(docEvent, document); final var data = cService.saveData(docEvent, document); extService.execute(data.getId(), docEvent.getId()); } </code>
@Async
@EventListener
@Transactional
public void handleUploadedFile(DocumentDto dto) {
    final var docEvent = cService.findEvent(documentDto);
    final var document = dRepository.findById(dto.getId()).orElseThrow();
    cService.saveUploadedDate(docEvent, document);
    final var data = cService.saveData(docEvent, document);
    extService.execute(data.getId(), docEvent.getId());
}

Load an event from a database using parent transaction. This part works.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public DocEvent findEvent(DocumentDto document) {
Integer periodId = document.getPeriod();
deRepository.findByPeriod(reportPeriodId).get(0);
}
</code>
<code>public DocEvent findEvent(DocumentDto document) { Integer periodId = document.getPeriod(); deRepository.findByPeriod(reportPeriodId).get(0); } </code>
public DocEvent findEvent(DocumentDto document) {
    Integer periodId = document.getPeriod();
    deRepository.findByPeriod(reportPeriodId).get(0);
}

I think that this new transaction is not neccessary here. This part works.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveUploadedDate(DocEvent docEvent, Document document) {
docEvent.setUploadedDate(LocalDateTime.now());
docEvent.setLoanDocument(document);
docEventRepository.save(docEvent);
}
</code>
<code>@Transactional(propagation = Propagation.REQUIRES_NEW) public void saveUploadedDate(DocEvent docEvent, Document document) { docEvent.setUploadedDate(LocalDateTime.now()); docEvent.setLoanDocument(document); docEventRepository.save(docEvent); } </code>
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveUploadedDate(DocEvent docEvent, Document document) {
    docEvent.setUploadedDate(LocalDateTime.now());
    docEvent.setLoanDocument(document);
    docEventRepository.save(docEvent);
}

Here I parse data and save them in a database. I use a new transaction because I need to commit data as an external service will consume them. This part works.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Transactional(propagation = Propagation.REQUIRES_NEW)
public Data saveData(DocEvent docEvent, Document loanDocument) {
verifyDocument(document);
var data = Data.builder().event(docEvent).build();
return dhRepository.save(data);
}
</code>
<code>@Transactional(propagation = Propagation.REQUIRES_NEW) public Data saveData(DocEvent docEvent, Document loanDocument) { verifyDocument(document); var data = Data.builder().event(docEvent).build(); return dhRepository.save(data); } </code>
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Data saveData(DocEvent docEvent, Document loanDocument) {
    verifyDocument(document);
    var data = Data.builder().event(docEvent).build();
    return dhRepository.save(data);
}

Here I consume an external service which is not ready yet, so I am testing a negative scenario, when feign client throws an exception. The problem is that processingStatus is not persisted. I also use a new transaction to avoid a rollback in the caller method.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Transactional(propagation = Propagation.REQUIRES_NEW)
public void execute(long dataId, long docEventId) {
final var data = dhRepository.findById(dataId).orElseThrow();
final var docEvent = deRepository.findById(docEventId).orElseThrow();
try {
final var request = ExternalRequest.builder().dataId(data.getId()).build();
final var body = objectMapper.writeValueAsString(request);
final var response = externalFeignClient.execute(body);
docEvent.setProcessingStatus(response.isSuccess() ? PROCESSING_SUCCESS : PROCESSING_ERROR);
deRepository.save(docEvent);
} catch (Exception e) {
log.error("Failed to execute for {}", e, data);
docEvent.setProcessingStatus(PROCESSING_ERROR);
docEventRepository.save(docEvent);
}
}
</code>
<code>@Transactional(propagation = Propagation.REQUIRES_NEW) public void execute(long dataId, long docEventId) { final var data = dhRepository.findById(dataId).orElseThrow(); final var docEvent = deRepository.findById(docEventId).orElseThrow(); try { final var request = ExternalRequest.builder().dataId(data.getId()).build(); final var body = objectMapper.writeValueAsString(request); final var response = externalFeignClient.execute(body); docEvent.setProcessingStatus(response.isSuccess() ? PROCESSING_SUCCESS : PROCESSING_ERROR); deRepository.save(docEvent); } catch (Exception e) { log.error("Failed to execute for {}", e, data); docEvent.setProcessingStatus(PROCESSING_ERROR); docEventRepository.save(docEvent); } } </code>
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void execute(long dataId, long docEventId) {
    final var data = dhRepository.findById(dataId).orElseThrow();
    final var docEvent = deRepository.findById(docEventId).orElseThrow();

    try {
        final var request = ExternalRequest.builder().dataId(data.getId()).build();
        final var body = objectMapper.writeValueAsString(request);
        final var response = externalFeignClient.execute(body);
        docEvent.setProcessingStatus(response.isSuccess() ? PROCESSING_SUCCESS : PROCESSING_ERROR);
        deRepository.save(docEvent);
    } catch (Exception e) {
        log.error("Failed to execute for {}", e, data);
        docEvent.setProcessingStatus(PROCESSING_ERROR);
        docEventRepository.save(docEvent);
    }
}

I can see in the debugger that it reached catch block and the processingStatus is updated. But when I load a row in DB, the value is null. Everytime. Here are hibernate logs:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Feign.RetryableException: Connection reset executing POST https://host/service/execute
TransactionImpl: committing
AbstractFlushingEventListener: Processing flush-time cascades
AbstractFlushingEventListener: Dirty checking collections
AbstractFlushingEventListener: Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects
AbstractFlushingEventListener: Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
EntityPrinter: Listing entities:
EntityPrinter: Data{}
EntityPrinter: DocEvent{processingStatus=ERROR}
update doc_event set processing_status=? where id=?
JdbcCoordinatorImpl: HHH000420: Closing un-released batch
</code>
<code>Feign.RetryableException: Connection reset executing POST https://host/service/execute TransactionImpl: committing AbstractFlushingEventListener: Processing flush-time cascades AbstractFlushingEventListener: Dirty checking collections AbstractFlushingEventListener: Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects AbstractFlushingEventListener: Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections EntityPrinter: Listing entities: EntityPrinter: Data{} EntityPrinter: DocEvent{processingStatus=ERROR} update doc_event set processing_status=? where id=? JdbcCoordinatorImpl: HHH000420: Closing un-released batch </code>
Feign.RetryableException: Connection reset executing POST https://host/service/execute
TransactionImpl: committing
AbstractFlushingEventListener: Processing flush-time cascades
AbstractFlushingEventListener: Dirty checking collections
AbstractFlushingEventListener: Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects
AbstractFlushingEventListener: Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
EntityPrinter: Listing entities:
EntityPrinter: Data{}
EntityPrinter: DocEvent{processingStatus=ERROR}
update doc_event set processing_status=? where id=?
JdbcCoordinatorImpl: HHH000420: Closing un-released batch

PS this is Spring boot application 2.7.16, Java 11, Oracle.

PS2 I tried to move that processing status update to another method with a new transaction similar to saveUploadedDate, and I later realized this worked. But my original approach shall work as well. I dont want to create so much transactions.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật