Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Table 'restaurant-service.food_menu' doesn't exist

I need to get all information about restaurant, but when Im doing a request, I have an error Table ‘restaurant-service.food_menu’ doesn’t exist, so I just don’t know how to fix it, but my post request is working excellent here is my database

Domain

Restaurant
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "Restaurant")
public class Restaurant {

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "RESTAURANT_ID")
    private Long id;

    private String restaurantName;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "restaurant")
    private List<FoodMenu> menu;

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "ADDRESS_ID")
    private Address address;

}

FoodMenu
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "FoodMenu")
public class FoodMenu {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "FOOD_MENU_ID")
    private Long id;

    private String foodName;

    private String foodDescription;

    private BigDecimal foodPrice;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "RESTAURANT_ID")
    private Restaurant restaurant;

}

Service
@Service
@Transactional
public class RestaurantService {
@Autowired
private RestaurantRepository restaurantRepository;

    public void saveRestaurant(Restaurant restaurant){
         restaurantRepository.save(restaurant);
    }

    public List<Restaurant> allRestaurants(){
        return restaurantRepository.findAll();
    }
}

Controller
@RestController
public class RestaurantController {

    @Autowired
    private RestaurantService restaurantService;

    @PostMapping("/create")
    public void createUploadRestaurant(@RequestBody Restaurant restaurant){
      restaurantService.saveRestaurant(restaurant);
    }

    @GetMapping("/showAllRestaurants")
    public List<Restaurant> showRestaurants(){
        return restaurantService.allRestaurants();
    }
}

>Solution :

The name you defined doesn’t match what you defined.

'restaurant-service.food_menu'  != @Table(name = "FoodMenu")
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "FoodMenu")
public class FoodMenu {
. . . .
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading