this is the Customer entity :
@Entity
@Table(name = "customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
...
}
OrderCreateDto :
public class OrderCreateDto {
private LocalDate orderDate;
private BigDecimal totalAmount;
private Long customerId;
...
}
and this is the create() method in the OrderService.java class :
public OrderDto create(OrderCreateDto dto) {
Order entity = mapper.toEntity(dto);
Order saved = repository.save(entity);
return mapper.toDto(saved);
}