why use Optional<MyClass> if you cant call any methods that MyClass has?

hey guys. can smb explain to me what wrong? im trying to retrieve an object from DB:
Optional<Payment> earlierPayment=paymentRepository.findByTransactionIdAndAmount(paymentConfirmationRequest.getTransactionId(), paymentConfirmationRequest.getAmount());
.

and for some reason i cant call any getters that my
Payment
entity has. does it mean that id need to change the return type of
findByTransactionIdAndAmount
from
Optional<Payment>
to just
Payment
? and then id loose the advantage
Optional
gives me. that doesnt make any sense ๐Ÿ˜ฆ

any help? thanks
Was this page helpful?