title: Spring Boot. how to Pass Optional<> to an Entity Class
body: <p>i am currently making a website using spring and i stumble upon this basic scenario that i don't have any idea on how to solve this specific code: Entity = Optional;</p>
  
  <pre><code>RoomEntity roomEntity =  roomRepository.findById(roomId);
  </code></pre>
  
  <p>ReservationResource(API request Class):</p>
  
  <pre><code>    public class ReservationResource {
      @Autowired
      RoomRepository roomRepository;
  
      @RequestMapping(path = "/{roomId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
      public ResponseEntity&lt;RoomEntity&gt; getRoomById(
      @PathVariable
      Long roomId){
          RoomEntity roomEntity =  roomRepository.findById(roomId);
          return new ResponseEntity&lt;&gt;(roomEntity, HttpStatus.OK);}
      }}
  </code></pre>
  
  <p>RoomRepository Class:</p>
  
  <pre><code>public interface RoomRepository extends CrudRepository&lt;RoomEntity, Long&gt; {
      List&lt;RoomEntity&gt; findAllById(Long id);
  }
  </code></pre>
  
  <p>RoomEntity</p>
  
  <pre><code>@Entity
  @Table(name = "Room")
  public class RoomEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @NotNull
      private Integer roomNumber;
  
      @NotNull
      private String price;
  
      public RoomEntity() {
          super();
      }
  }
  </code></pre>