在我的具体案例中 ORM 模型和 DAO
我的数据库结构如下:
表STUDENT(例如,id,姓氏等)
表STUDENT_PROPERTIES(例如,name_of_the_property:char,value_of_the_property:char,student_id:FK)
表COURSE(id,name,statusofcourse_id)
表STATUSOFSOMETHING(id, name_of_status:char ('active','inactive','suspended' etc))
table STUDENT_COURSE (student_id,course_id,statusofsomething_id)
让我们尝试在我的数据库中选取域对象:
Student 和 Course 是主要实体。 学生有一个他参加的课程列表,还有一个属性列表,这就是该学生的全部内容。
接下来,课程实体。它可能包含参加该课程的学生列表。
但实际上,整个结构是这样的:起点是Student,它是PK 我们可以查看他的属性列表, 然后我们查看 STUDENT_COURSE 并提取课程实体的 FK 以及状态 的组合,它看起来像“名为 bla bla 的学生,拥有他的所有属性, 参加数学,其状态为“ACTIVE”。
现在,引用
1) 每个 DAO 实例负责一个主域对象或实体。如果一个领域对象有独立的生命周期,它就应该有自己的DAO。
2) DAO 负责域对象的创建、读取(通过主键)、更新和删除(即 CRUD)。
现在,第一个问题是 我的案例中的实体是什么? 学生、课程、Student_Course、状态 = 除了 StudentProperties 之外的所有内容? 我是否必须为每个对象创建一个单独的 DAO?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建的实体是:
StudentCourse 不需要创建,因为您可以在中使用多对多映射Hibernate 将为您的 Student 对象提供一组很好的课程。
这是一个关于休眠映射的很棒的教程,它几乎可以完成您需要的一切:
http://www.vaannila。 com/hibernate/hibernate-example/hibernate-mapping-many-to-many-1.html
The entities you will need to create are:
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