views:

61

answers:

1

I have the DB structure as follows:

table STUDENT (say, id, surname, etc)

table STUDENT_PROPERTIES (say, name_of_the_property:char, value_of_the_property:char, student_id:FK)

table COURSE (id, name, statusofcourse_id)

table STATUSOFSOMETHING (id, name_of_status:char ('active','inactive','suspended' etc))

table STUDENT_COURSE (student_id,course_id,statusofsomething_id)

Let's try to pick up domain objects in my database:

Student and Course are main entities. Student has a list of courses he attends, also he has a list of properties, that is all for this student.

Next, Course entitity. It may contain a list of students that attend it.

But in fact, the whole structure looks like this: the starting point is Student, with it's PK we can look a list of his properties, then we look into the STUDENT_COURSE and extract both FK of the Course entity and also the Status of the combination, it would look like "Student named bla bla, with all his properties, attends math and the status of it is "ACTIVE".

now, quotation

1) Each DAO instance is responsible for one primary domain object or entity. If a domain object has an independent lifecycle, it should have its own DAO.

2) The DAO is responsible for creations, reads (by primary key), updates, and deletions -- that is, CRUD -- on the domain object.

Now, first question is What are entities in my case? Student, Course, Student_Course, Status = all except for StudentProperties? Do I have to create a separate DAO for every object?

+1  A: 

The entities you will need to create are:

  • Student
  • StudentProperties
  • Course
  • CourseStatus (not really necessary as you could use an enumerated field in Course instead)

StudentCourse doesn't need to be created, as you can just use a Many-to-Many mapping in Hibernate and it will give you a nice set of courses in your Student object.

Here's a great tutorial on hibernate mapping that does pretty much everything you need: http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-many-1.html

James
@James Goodwin Probably, but is it ok that there are not only student_id and course_id, but also the third field, status_id that defines a row in the table? In fact, that Status field does not belong to the Course, it exists completely independently. Only its value in STUDENT_COURSE makes sense.
EugeneP