18 Linking Objects Between Two Service Builder Portlets

In order to use an object you, or another team member has created using Service Builder in some other portlet somewhere (for instance, the re-usable Department or Person objects) you'll need to do a few things...

Service.xml files:

Firstly, remember that the foreign key definition in Service Builder is backwards, so for instance, where a Course belongs to a Department, the logical foreign key on Course (Department_ID) exists, but also, a Collection of Courses is defined on Department. Although this looks like a column in Service Builder, it won't exist in the database, it's just there for SB to do its thing.

The foreign key (Department_ID) on the Course table only needs to be of type "long" (as all PKs are type long) and needs to make no reference to the Department table. The Collection of Courses on the Department table however must be identified in the entity field, so "uk.ac.uea.portlet.CourseCatalogue.Course". The mapping key is the name of the foreign key field on Course, so "Department_ID".

As we've referenced the new "Course" type on the Department entity, SB needs to know what a Course is. This is achieved by adding a reference (drop-down menu under the Department entity in Dev Studio). Type: Course, package path: uk.ac.uea.portlet.CourseCatalogue.

SB won't be able to find the other portlet however, you'll need to embed its "service.xml" into the portlet you're developing. Service builder starts looking in "docroot/WEB-INF/src" and will follow the package path defined, replacing '.' with '/'. So, using the above configuration, the "service.xml" from the CourseCatalogue portlet needs to be placed in "/docroot/WEB-INF/src/uk/ac/uea/portlet/CourseCatalogue" within the Department portlet.

Service Builder should now be able to build the links and create the required helper methods like "getCourses" in the DepartmentPersistenceImpl.java.

Please note that SB will generate code that doesn't work and will prevent the portlet from deploying. Development ongoing.