One foreign key point to multiple primary key
Visual Paradigm ORM code generation now support one foreign key associating to multiple primary keys.
Entity Relationship Diagram
From the above ERD, college_id of Student point to another two entities college_id
Generating Class Diagram from Entity Relationship Diagram
Then generate it to Class Diagram by following ways:
Right Click on the
Diagram →
Synchronize to Class Diagram
or hold down the right-mouse button, move the mouse to form the
right-left gesture indicated by the blue path on the Entity Relationship Diagram.

Specifying which association support setter method
Since the Student table have more than one foreign key referenced, during the synchronization from ERD to Class Diagram, a Conflit dialog box will be shown
Department = > Student
if choosing this one, Department information can be set and retrieve from Student. And College for Student becomes readonly.
College = > Student
if choosing this one, College information can now be set and retrieve from Student, and the Department for Student can be readonly.
In this example, we will select Department = > Student as our choice
Animated Demo
Generating code from Class Diagram
Select from the menu bar
Tools →
Object-Relation Mapping(ORM) →
Wizards...
Choose
Generate Code and Database from Class Diagram then click on
Next Button

Select Classes needed for generating Database table

View table details and change code style if necessary

setup
Database Configuration, we are using MySQL Database as an example

To Test the successful of Database configuration, click on the
Test Connection Button. If connected to Database successfully, the below dialog will be shown.

Select the
outputpath and the
application type for the usage of generated code

Click on
Close button when code and database generated successfully.

Using ORM generated code
//Create a College First
College college = CollegeFactory.createCollege();
college.setName("College A");
//Then create two department
Department department1 = DepartmentFactory.createDepartment();
Department1.setDept_id(1);
department1.setName("Department A");
department1.setCollege(college);
Department department2 = DepartmentFactory.createDepartment();
department2.setDept_id(2);
department2.setName("Department B");
department2.setCollege(college);
//And add few student to each department
Student student1 = StudentFactory.createStudent();
student1.setAge(21);
student1.setGender('M');
student1.setName("Student A");
student1.setDepartment(department1);
Student student2 = StudentFactory.createStudent();
student2.setAge(21);
student2.setGender('F');
student2.setName("Student B");
student2.setDepartment(department2);
college.save();
// Load a student from Database
Student student = StudentFactory.loadStudentByQuery("name='Student A'",null);
College college = student.getCollege1();
Department department = student.getDepartment();
System.out.println(college.getName());
System.out.println(department.getName());
College A
Department A
Downloads