I have two different tables, Pizza and User. First of all, when I create the first entity from for example the user, ID is 1. After that, when I want to create a Pizza, the ID of it will be 2. They sharing the ID somehow. How can I fix that?
And my other question, I have a third table, named Orders. I managed to ask on Order creating for the valid User and Pizza ID, but I just wanna know, what would be the best solution for it? I just created the Pizza and User Service object in the Order Controller as well, and refered from there. But I don't know how bad is it.
Thank you for the answers!
@Entity(name = "pizza")
@Table(name = "pizza")
public class Pizza {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull
private String type;
@Entity(name = "users")
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull
private String email;
@NotNull
private String address;
@Entity(name = "orders")
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull
private int user_id;
@NotNull
private int pizza_id;
@RestController
public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private UserService userService;
@Autowired
private PizzaService pizzaService;