Spring boot REST API
I create two entity in Student
package com.practice.lab.entities;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import java.util.List;
@Entity
@Getter
@Setter
@NoArgsConstructor
@ToString
public class Student extends BaseEntity{
String name;
double marks;
int age;
@OneToMany(mappedBy = "student" , cascade = CascadeType.ALL, orphanRemoval = true)
List<Bike> bike;
public Student(String name, double marks, int age) {
this.name = name;
this.marks = marks;
this.age = age;
}
}
then I have another entity Bike
package com.practice.lab.entities;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
@Entity
@Getter
@Setter
@NoArgsConstructor
@ToString
public class Bike extends BaseEntity{
String companyname;
int model;
double price;
@ManyToOne
@JoinColumn(name = "stu_id")
Student student;
}
"inside my StudentController"
@GetMapping
public List<Student> fetchAllStudent(){
System.out.println("Fetching all student");
return studentService.getAllStudent();
}
@PostMapping
public User addUser(@RequestBody User user){
System.out.println("Adding emp");
return userService.addUserDetails(user);
}
enter image description here POST request to add Student with bike
enter image description here Students and Bike added but id not added in table
Why am I not getting Student id in Bike table