title: java.util.NoSuchElementException: No value present Spring JPA
body: <p>I am relatively new in the world of Spring Boot and I have a problem with storing the data in database in my project. I have these entities: Flight - (flight number, gate, airport departure, airport arrival etc.), Passenger (passport number, name, surname etc.), Ticket( ticket number, passport_number(foreign key referencing Passenger table), flight_number(foreign key referencing Flight table)) and Luggage(id, ticket number(foreign key referencing Ticket table). When I want to make a reservation, first I want to save the data about the passenger, then save the data about the ticket(using the passport_number of the new passenger) and at the end to save the data about the luggage(also using the passport_number of the new passenger) and I want the whole process to be like a transaction. But I constantly get an error <strong>java.util.NoSuchElementException: No value present
  at java.base/java.util.Optional.get(Optional.java:141) ~[na:na]</strong> when I am saving the passenger. Here is the code. Any suggestions how can I solve this problem?  Here is the code from the controller where I am trying to save the data. Thank you so much.</p>
  <pre><code>  @PostMapping(&quot;/confirmTicket&quot;)
      @Transactional
      public String confirmTicket(HttpServletRequest req) {
          Passenger passenger = (Passenger) req.getSession().getAttribute(&quot;passenger&quot;);
          Flight flight = (Flight) req.getSession().getAttribute(&quot;flight&quot;);
  
          Passenger passengerNew = passengerService.save(passenger.getPassport_number(), passenger.getFirst_name(), passenger.getLast_name(),
                  passenger.getEmail(), passenger.getAddress(), passenger.getPhone_number(), passenger.getAccount_number()).get();
  
  
          Ticket ticket = ticketService.save(Integer.parseInt(req.getSession().getAttribute(&quot;seat&quot;).toString()), flight.getPrice(),
                  Class.valueOf(req.getSession().getAttribute(&quot;class&quot;).toString()), &quot;&quot;, passengerNew, flight).get();
  
  
          luggageService.save(LuggageType.valueOf(req.getSession().getAttribute(&quot;luggage&quot;).toString()),
                  Integer.parseInt(req.getSession().getAttribute(&quot;weight&quot;).toString()), ticket);
  
          return &quot;redirect:/home&quot;;
      }
  </code></pre>