How to make a relation between two objects in database JAVA












1















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 again!");
break;
}

}

}


private void createNewDiscipline(String details) {
int hours=Integer.parseInt(details[1]);
repository1.save(new Discipline(details[0],hours));
}

private void printAllDisciplines() {

Iterable<Discipline> allDisciplines = repository1.findAll();

for (Discipline discipline : allDisciplines) {
System.out.println(discipline);
}
}

private void createNewStudent(String details) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDate localDate = LocalDate.parse(details[1], dtf);
repository.save(new Student(details[0],localDate));
}

private void printAllStudents() {

Iterable<Student> allStudents = repository.findAll();

for (Student student : allStudents) {
System.out.println(student);
}
}

private void studendAndDiscipline(String details) {
int studentId=Integer.parseInt(details[1]);
int disciplineId=Integer.parseInt(details[2]);
Student student=repository.findById(studentId);
Discipline discipline=repository1.findById(disciplineId);
student.addDiscipline(discipline);
}


}



In studentAndDiscipline I have to create a relation between a student and a discipline both by ID, but I am doing it wrong. I tried using Optional<>, but it doesn't work either.



My Student class:
@Entity
class Student {



@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;


private String name;
private LocalDate enrollmentDate;

@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
List<Discipline> disciplines;


private Student() {
// Required by Hibernate
}
public Student(String name, LocalDate enrollmentDate) {
this.name = name;
this.enrollmentDate = enrollmentDate;
}

void addDiscipline(Discipline discipline) {
this.disciplines.add(discipline);
}

@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + ''' +
", enrollmentDate=" + enrollmentDate +
", disciplines=" + disciplines +
'}';
}


}



My Discipline Class:
@Entity
class Discipline {



@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;


String name;
int credits;

private Discipline() {
// Required by Hibernate
}
public Discipline(String name, int credits) {
this.name = name;
this.credits = credits;
}

@Override
public String toString() {
return "Discipline{" +
"id=" + id +
", name='" + name + ''' +
", credits=" + credits +
'}';
}


}



My StudentRepository:



interface StudentRepository extends CrudRepository<Student, Integer> {


}



My DisciplineRepository:



interface DisciplineRepository extends CrudRepository<Discipline, Integer> {


}










share|improve this question





























    1















    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 again!");
    break;
    }

    }

    }


    private void createNewDiscipline(String details) {
    int hours=Integer.parseInt(details[1]);
    repository1.save(new Discipline(details[0],hours));
    }

    private void printAllDisciplines() {

    Iterable<Discipline> allDisciplines = repository1.findAll();

    for (Discipline discipline : allDisciplines) {
    System.out.println(discipline);
    }
    }

    private void createNewStudent(String details) {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
    LocalDate localDate = LocalDate.parse(details[1], dtf);
    repository.save(new Student(details[0],localDate));
    }

    private void printAllStudents() {

    Iterable<Student> allStudents = repository.findAll();

    for (Student student : allStudents) {
    System.out.println(student);
    }
    }

    private void studendAndDiscipline(String details) {
    int studentId=Integer.parseInt(details[1]);
    int disciplineId=Integer.parseInt(details[2]);
    Student student=repository.findById(studentId);
    Discipline discipline=repository1.findById(disciplineId);
    student.addDiscipline(discipline);
    }


    }



    In studentAndDiscipline I have to create a relation between a student and a discipline both by ID, but I am doing it wrong. I tried using Optional<>, but it doesn't work either.



    My Student class:
    @Entity
    class Student {



    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;


    private String name;
    private LocalDate enrollmentDate;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    List<Discipline> disciplines;


    private Student() {
    // Required by Hibernate
    }
    public Student(String name, LocalDate enrollmentDate) {
    this.name = name;
    this.enrollmentDate = enrollmentDate;
    }

    void addDiscipline(Discipline discipline) {
    this.disciplines.add(discipline);
    }

    @Override
    public String toString() {
    return "Student{" +
    "id=" + id +
    ", name='" + name + ''' +
    ", enrollmentDate=" + enrollmentDate +
    ", disciplines=" + disciplines +
    '}';
    }


    }



    My Discipline Class:
    @Entity
    class Discipline {



    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;


    String name;
    int credits;

    private Discipline() {
    // Required by Hibernate
    }
    public Discipline(String name, int credits) {
    this.name = name;
    this.credits = credits;
    }

    @Override
    public String toString() {
    return "Discipline{" +
    "id=" + id +
    ", name='" + name + ''' +
    ", credits=" + credits +
    '}';
    }


    }



    My StudentRepository:



    interface StudentRepository extends CrudRepository<Student, Integer> {


    }



    My DisciplineRepository:



    interface DisciplineRepository extends CrudRepository<Discipline, Integer> {


    }










    share|improve this question



























      1












      1








      1








      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 again!");
      break;
      }

      }

      }


      private void createNewDiscipline(String details) {
      int hours=Integer.parseInt(details[1]);
      repository1.save(new Discipline(details[0],hours));
      }

      private void printAllDisciplines() {

      Iterable<Discipline> allDisciplines = repository1.findAll();

      for (Discipline discipline : allDisciplines) {
      System.out.println(discipline);
      }
      }

      private void createNewStudent(String details) {
      DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
      LocalDate localDate = LocalDate.parse(details[1], dtf);
      repository.save(new Student(details[0],localDate));
      }

      private void printAllStudents() {

      Iterable<Student> allStudents = repository.findAll();

      for (Student student : allStudents) {
      System.out.println(student);
      }
      }

      private void studendAndDiscipline(String details) {
      int studentId=Integer.parseInt(details[1]);
      int disciplineId=Integer.parseInt(details[2]);
      Student student=repository.findById(studentId);
      Discipline discipline=repository1.findById(disciplineId);
      student.addDiscipline(discipline);
      }


      }



      In studentAndDiscipline I have to create a relation between a student and a discipline both by ID, but I am doing it wrong. I tried using Optional<>, but it doesn't work either.



      My Student class:
      @Entity
      class Student {



      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;


      private String name;
      private LocalDate enrollmentDate;

      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      List<Discipline> disciplines;


      private Student() {
      // Required by Hibernate
      }
      public Student(String name, LocalDate enrollmentDate) {
      this.name = name;
      this.enrollmentDate = enrollmentDate;
      }

      void addDiscipline(Discipline discipline) {
      this.disciplines.add(discipline);
      }

      @Override
      public String toString() {
      return "Student{" +
      "id=" + id +
      ", name='" + name + ''' +
      ", enrollmentDate=" + enrollmentDate +
      ", disciplines=" + disciplines +
      '}';
      }


      }



      My Discipline Class:
      @Entity
      class Discipline {



      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;


      String name;
      int credits;

      private Discipline() {
      // Required by Hibernate
      }
      public Discipline(String name, int credits) {
      this.name = name;
      this.credits = credits;
      }

      @Override
      public String toString() {
      return "Discipline{" +
      "id=" + id +
      ", name='" + name + ''' +
      ", credits=" + credits +
      '}';
      }


      }



      My StudentRepository:



      interface StudentRepository extends CrudRepository<Student, Integer> {


      }



      My DisciplineRepository:



      interface DisciplineRepository extends CrudRepository<Discipline, Integer> {


      }










      share|improve this question
















      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 again!");
      break;
      }

      }

      }


      private void createNewDiscipline(String details) {
      int hours=Integer.parseInt(details[1]);
      repository1.save(new Discipline(details[0],hours));
      }

      private void printAllDisciplines() {

      Iterable<Discipline> allDisciplines = repository1.findAll();

      for (Discipline discipline : allDisciplines) {
      System.out.println(discipline);
      }
      }

      private void createNewStudent(String details) {
      DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
      LocalDate localDate = LocalDate.parse(details[1], dtf);
      repository.save(new Student(details[0],localDate));
      }

      private void printAllStudents() {

      Iterable<Student> allStudents = repository.findAll();

      for (Student student : allStudents) {
      System.out.println(student);
      }
      }

      private void studendAndDiscipline(String details) {
      int studentId=Integer.parseInt(details[1]);
      int disciplineId=Integer.parseInt(details[2]);
      Student student=repository.findById(studentId);
      Discipline discipline=repository1.findById(disciplineId);
      student.addDiscipline(discipline);
      }


      }



      In studentAndDiscipline I have to create a relation between a student and a discipline both by ID, but I am doing it wrong. I tried using Optional<>, but it doesn't work either.



      My Student class:
      @Entity
      class Student {



      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;


      private String name;
      private LocalDate enrollmentDate;

      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      List<Discipline> disciplines;


      private Student() {
      // Required by Hibernate
      }
      public Student(String name, LocalDate enrollmentDate) {
      this.name = name;
      this.enrollmentDate = enrollmentDate;
      }

      void addDiscipline(Discipline discipline) {
      this.disciplines.add(discipline);
      }

      @Override
      public String toString() {
      return "Student{" +
      "id=" + id +
      ", name='" + name + ''' +
      ", enrollmentDate=" + enrollmentDate +
      ", disciplines=" + disciplines +
      '}';
      }


      }



      My Discipline Class:
      @Entity
      class Discipline {



      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;


      String name;
      int credits;

      private Discipline() {
      // Required by Hibernate
      }
      public Discipline(String name, int credits) {
      this.name = name;
      this.credits = credits;
      }

      @Override
      public String toString() {
      return "Discipline{" +
      "id=" + id +
      ", name='" + name + ''' +
      ", credits=" + credits +
      '}';
      }


      }



      My StudentRepository:



      interface StudentRepository extends CrudRepository<Student, Integer> {


      }



      My DisciplineRepository:



      interface DisciplineRepository extends CrudRepository<Discipline, Integer> {


      }







      java database oop






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 2:15







      Nikola Hristov

















      asked Nov 20 '18 at 0:47









      Nikola HristovNikola Hristov

      83




      83
























          1 Answer
          1






          active

          oldest

          votes


















          0














          private void studendAndDiscipline(String details) {
          int studentId=Integer.parseInt(details[1]);
          int disciplineId=Integer.parseInt(details[2]);
          Student student=repository.findById(studentId);
          Discipline discipline=repository1.findById(disciplineId);
          student.addDiscipline(discipline);
          }


          Discipline discipline=repository1.findById(disciplineId);, is not right. findById(ID id) would return Optional<T> type, you need to use get() to get the T.
          And you should make sure discipline is not null. At least you need to check it like



          Student student=repository.findById(studentId).get();
          Discipline discipline=repository1.findById(disciplineId).get();
          if (discipline != null) {
          student.addDiscipline(discipline);
          System.out.println("Adding discipline to student.");
          }


          If you are sure discipline is not null, you need to check addDiscipline() implementation.






          share|improve this answer


























          • The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

            – Nikola Hristov
            Nov 20 '18 at 1:25











          • please add Student, Discipline and StudentRepository

            – Bejond
            Nov 20 '18 at 1:51













          • I have added it to my original post. Thanks for helping me.

            – Nikola Hristov
            Nov 20 '18 at 2:16











          • updated answer.

            – Bejond
            Nov 20 '18 at 2:23











          • thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

            – Nikola Hristov
            Nov 20 '18 at 3:15











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384684%2fhow-to-make-a-relation-between-two-objects-in-database-java%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          private void studendAndDiscipline(String details) {
          int studentId=Integer.parseInt(details[1]);
          int disciplineId=Integer.parseInt(details[2]);
          Student student=repository.findById(studentId);
          Discipline discipline=repository1.findById(disciplineId);
          student.addDiscipline(discipline);
          }


          Discipline discipline=repository1.findById(disciplineId);, is not right. findById(ID id) would return Optional<T> type, you need to use get() to get the T.
          And you should make sure discipline is not null. At least you need to check it like



          Student student=repository.findById(studentId).get();
          Discipline discipline=repository1.findById(disciplineId).get();
          if (discipline != null) {
          student.addDiscipline(discipline);
          System.out.println("Adding discipline to student.");
          }


          If you are sure discipline is not null, you need to check addDiscipline() implementation.






          share|improve this answer


























          • The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

            – Nikola Hristov
            Nov 20 '18 at 1:25











          • please add Student, Discipline and StudentRepository

            – Bejond
            Nov 20 '18 at 1:51













          • I have added it to my original post. Thanks for helping me.

            – Nikola Hristov
            Nov 20 '18 at 2:16











          • updated answer.

            – Bejond
            Nov 20 '18 at 2:23











          • thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

            – Nikola Hristov
            Nov 20 '18 at 3:15
















          0














          private void studendAndDiscipline(String details) {
          int studentId=Integer.parseInt(details[1]);
          int disciplineId=Integer.parseInt(details[2]);
          Student student=repository.findById(studentId);
          Discipline discipline=repository1.findById(disciplineId);
          student.addDiscipline(discipline);
          }


          Discipline discipline=repository1.findById(disciplineId);, is not right. findById(ID id) would return Optional<T> type, you need to use get() to get the T.
          And you should make sure discipline is not null. At least you need to check it like



          Student student=repository.findById(studentId).get();
          Discipline discipline=repository1.findById(disciplineId).get();
          if (discipline != null) {
          student.addDiscipline(discipline);
          System.out.println("Adding discipline to student.");
          }


          If you are sure discipline is not null, you need to check addDiscipline() implementation.






          share|improve this answer


























          • The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

            – Nikola Hristov
            Nov 20 '18 at 1:25











          • please add Student, Discipline and StudentRepository

            – Bejond
            Nov 20 '18 at 1:51













          • I have added it to my original post. Thanks for helping me.

            – Nikola Hristov
            Nov 20 '18 at 2:16











          • updated answer.

            – Bejond
            Nov 20 '18 at 2:23











          • thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

            – Nikola Hristov
            Nov 20 '18 at 3:15














          0












          0








          0







          private void studendAndDiscipline(String details) {
          int studentId=Integer.parseInt(details[1]);
          int disciplineId=Integer.parseInt(details[2]);
          Student student=repository.findById(studentId);
          Discipline discipline=repository1.findById(disciplineId);
          student.addDiscipline(discipline);
          }


          Discipline discipline=repository1.findById(disciplineId);, is not right. findById(ID id) would return Optional<T> type, you need to use get() to get the T.
          And you should make sure discipline is not null. At least you need to check it like



          Student student=repository.findById(studentId).get();
          Discipline discipline=repository1.findById(disciplineId).get();
          if (discipline != null) {
          student.addDiscipline(discipline);
          System.out.println("Adding discipline to student.");
          }


          If you are sure discipline is not null, you need to check addDiscipline() implementation.






          share|improve this answer















          private void studendAndDiscipline(String details) {
          int studentId=Integer.parseInt(details[1]);
          int disciplineId=Integer.parseInt(details[2]);
          Student student=repository.findById(studentId);
          Discipline discipline=repository1.findById(disciplineId);
          student.addDiscipline(discipline);
          }


          Discipline discipline=repository1.findById(disciplineId);, is not right. findById(ID id) would return Optional<T> type, you need to use get() to get the T.
          And you should make sure discipline is not null. At least you need to check it like



          Student student=repository.findById(studentId).get();
          Discipline discipline=repository1.findById(disciplineId).get();
          if (discipline != null) {
          student.addDiscipline(discipline);
          System.out.println("Adding discipline to student.");
          }


          If you are sure discipline is not null, you need to check addDiscipline() implementation.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 2:22

























          answered Nov 20 '18 at 1:08









          BejondBejond

          890515




          890515













          • The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

            – Nikola Hristov
            Nov 20 '18 at 1:25











          • please add Student, Discipline and StudentRepository

            – Bejond
            Nov 20 '18 at 1:51













          • I have added it to my original post. Thanks for helping me.

            – Nikola Hristov
            Nov 20 '18 at 2:16











          • updated answer.

            – Bejond
            Nov 20 '18 at 2:23











          • thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

            – Nikola Hristov
            Nov 20 '18 at 3:15



















          • The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

            – Nikola Hristov
            Nov 20 '18 at 1:25











          • please add Student, Discipline and StudentRepository

            – Bejond
            Nov 20 '18 at 1:51













          • I have added it to my original post. Thanks for helping me.

            – Nikola Hristov
            Nov 20 '18 at 2:16











          • updated answer.

            – Bejond
            Nov 20 '18 at 2:23











          • thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

            – Nikola Hristov
            Nov 20 '18 at 3:15

















          The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

          – Nikola Hristov
          Nov 20 '18 at 1:25





          The problem is that the program doesn't compile at all. At Student student and Discipline discipline I get incompatible types. Student student says required Student, found Optional and Discipline discipline says required Discipline, found optional.

          – Nikola Hristov
          Nov 20 '18 at 1:25













          please add Student, Discipline and StudentRepository

          – Bejond
          Nov 20 '18 at 1:51







          please add Student, Discipline and StudentRepository

          – Bejond
          Nov 20 '18 at 1:51















          I have added it to my original post. Thanks for helping me.

          – Nikola Hristov
          Nov 20 '18 at 2:16





          I have added it to my original post. Thanks for helping me.

          – Nikola Hristov
          Nov 20 '18 at 2:16













          updated answer.

          – Bejond
          Nov 20 '18 at 2:23





          updated answer.

          – Bejond
          Nov 20 '18 at 2:23













          thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

          – Nikola Hristov
          Nov 20 '18 at 3:15





          thanks a lot. It now compiles, but I get "ArrayIndexOutOfBoundsException: 2"

          – Nikola Hristov
          Nov 20 '18 at 3:15


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384684%2fhow-to-make-a-relation-between-two-objects-in-database-java%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$