@Transactional is not working when it tagged on the method created using functional interfaces

40 Views Asked by At

I created a method in my service implementation & annotated by Transactional class. but @Transactional is no effective when then method is created as functional interfaces such as BiFunction, Function, BiConsumer, etc...

But when I change the method syntax to the traditional approach, its working like a charm. Can anyone help on this to understand the root cause? Thanks in advance!

Method created in function interface approach,

@Override
@Transactional
public BiFunction<Header, InvoiceHeaderReq, Response<Long>> generateInvoice()  {

    return (header, req) -> {
        try {
            /* validate invoice header */
            invHeaderValidation.get().invoiceShouldNotExistById.accept(header, req.getInvoiceHeaderId());

            /* get customer address, payment info, currency & update in the same {@code req}  */
            req = findMiscInvoiceHeaderInfo.apply(header, req);

            /* prepare invoice header entity & create new invoice */
            req.setInvoiceNumber(getInvoiceNumber.apply(header));
            InvoiceHeader invHeaderEnt = prepareInvHeaderEntity
                    .andThen(ent -> invHeaderRepo.get().save(ent))
                    .apply(header, req);
        }
    };
}

Method created in traditional approach,

@Override
@Transactional
public Response<Long> generateInvoice(Header header, InvoiceHeaderReq req)  {

    try {
        /* validate invoice header */
        invHeaderValidation.get().invoiceShouldNotExistById.accept(header, req.getInvoiceHeaderId());

        /* get customer address, payment info, currency & update in the same {@code req}  */
        req = findMiscInvoiceHeaderInfo.apply(header, req);

        /* prepare invoice header entity & create new invoice */
        req.setInvoiceNumber(getInvoiceNumber.apply(header));
        InvoiceHeader invHeaderEnt = prepareInvHeaderEntity
                .andThen(ent -> invHeaderRepo.get().save(ent))
                .apply(header, req);
    }
}
0

There are 0 best solutions below