ORM(Object Relational Mapping) in Hibernate
是您澄清的好例子!
对于像这样的问题:Is a class diagram essentially a database design? and Are classes the equivalent to tables and their attributes equivalent to columns?
..是的,让我和你解释一个例子:
class Department
{
private int departmentNo;
private int departmentName;
private Set<Student> students;
}
class Student
{
private int studentId;
private int studentName;
private Department department;
}
使用这些实体,
Two database tables
将使用 hibernate 生成。默认情况下,
Department: departmentno(int),departmentname(varchar(255))
Student: studentid(int), studentname(varchar(255)),departmentno(int) [foreign key]
被生成。
可以通过以下方式检索特定部门的学生列表,
Department department = ......; // hibernate related thing which hit the database
Set<Student> = department.getStudents();