I have two classes: Student and Group.
Student attributes:
private String registrationNumber;
private String firstName;
private String lastName;
private Date dateOfBirth;
private String password;
private Groupe groupe;
private List<Grades> studentGrades;
Student Constructor:
public Student(String registrationNumber, String firstName, String lastName, Date dateOfBirth, Groupe groupe,String password) {
super();
this.registrationNumber = registrationNumber;
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.groupe = groupe;
this.password=password;
}
Group attributes:
private int idGroup;
private String nameGroup;
private List<Student> students;
private List<Subject> subjects;
Its constructor takes only idGroup and nameGroup.
When registering, a student will select a group from a drop down menu (Swing interface) which will then call the addStudent function (controller to DAO).
public boolean addStudent( Student s) throws SQLException {
myStatement=myConnection.getMyConnection().createStatement();
String request="insert into student values('"+s.getRegistrationNumber()+"','"+s.getFirstName()+"','"+s.getLastName()+"','"+s.getDateOfBirth()+"','"+s.getPassword()+"')";
return myStatement.executeUpdate(request)>0;
}
Which is currently missing the group attribute.
How should I translate the group attribute (and by extension all other associations) from OOP to a relational format?
Should I drop these association from student and use an int attribute that represents a foreign key which refrences the Group table's primary key and rely on joins for the List (1..n associations)?
Studentreferences aGroupthrough a foreign key. But no, notint. In OOP, this is a reference to aGroup. Don't use any special fields or properties. to translate to the relational database. Your data types should remain pure OOP. Keep to the S.P.O.T. principle (Single Point of Truth).Date- it's obsolete b. Don't reinvent the wheel of OR mapping c. Use try-with-resources for your DB objects (but see b. too) d. Don't be Little Bobby Tablesprivate Groupe groupe;it is the real equivalent of the relational database relation.