How to make a relation between two objects in database JAVA

I am currently trying to create a relation between my Student class and my Discipline class. This is what I am doing:

@Service

public class StudentRegistrationService implements ApplicationRunner {

private final StudentRepository repository;

private final DisciplineRepository repository1;

public StudentRegistrationService(StudentRepository repository, DisciplineRepository repository1) {

this.repository = repository;

this.repository1 = repository1;

}

@Override

public void run(ApplicationArguments args) throws Exception {

Scanner scanner = new Scanner(System.in);

while (true) {

String input = scanner.nextLine();

String[] split = input.split(" ");

String command = split[0];

switch (command.toUpperCase()) {

case "END":

System.out.println("bye bye");

return;

case "STUDLIST":

printAllStudents();

break;

case "STUDNEW":

String[] studentDetails = Arrays.copyOfRange(split, 1, split.length);

createNewStudent(studentDetails);

break;

case "DISCLIST":

printAllDisciplines();

break;

case "DISCNEW":

String[] disciplineDetails = Arrays.copyOfRange(split, 1, split.length);

createNewDiscipline(disciplineDetails);

break;

case "STUDDISC":

String[] studentAndDisciplineId = Arrays.copyOfRange(split, 1, split.length);

studendAndDiscipline(studentAndDisciplineId);

break;

default:

System.out.println("UNKNOWN command, try...

Read More »

By: StackOverFlow - Monday, 19 November

Related Posts

  • Older News
  • Hibernate LazyInitialization @OneToOne StackOverFlow (Yesterday) - I have a problem to eagerly load through a join fetch a relation marked as lazy.@ManyToOne(fetch=FetchType.LAZY)@LazyToOne(LazyToOneOption.NO_PROXY)@JoinColumn(name = "type_id")private TypeEntity type;Because of performance issue we are currently moving all properties which...