留言板

Table mapping relationship in service builder

Alex Man,修改在7 年前。

Table mapping relationship in service builder

Junior Member 帖子: 70 加入日期: 16-2-8 最近的帖子
I have created a service builder which is having three entities Employee, EmployeeColorConfig and Color. EmployeeColorConfig is the entity which binds both the other entities (Employee and Color). The relationship is as given below in the diagram



I have created my service builder like as shown below but dont know how to make the mapping relationship.

<service-builder package-path="com.sample">
	<author>user</author>
	<namespace>sample</namespace>
	<entity name="Employee" local-service="true" remote-service="false" json-enabled="true">
		<column name="empId" type="long" primary="true" id-type="increment" />
		<column name="empName" type="String" />
	</entity>
	
	<entity name="EmployeeColorConfig" local-service="true" remote-service="false" json-enabled="true">
		<column name="id" type="long" primary="true" id-type="increment" />
		<column name="empId" type="long" />
		<column name="colorId" type="long" />
	</entity>
	
	<entity name="Color" local-service="true" remote-service="false">
		<column name="colorId" type="long" primary="true" id-type="increment" />
		<column name="colorName" type="String" />
	</entity>
</service-builder>


Can anyone please tell me how to make up the mappings within the service builder for the above scenario
thumbnail
David H Nebinger,修改在7 年前。

RE: Table mapping relationship in service builder

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
SB is not going to handle this for you because of the extra id on the join table.

If you build a classic "many to many" relationship, SB will create and manage the join table with just the primary keys.

To implement the way you want, you actually have to build two "one to many" relationships, one in each entity that refers to the many from the join table. Then you have to manage the join table on your own.

The added wrinkle you haven't hit yet is that SB does not pass the child lists across the class loader boundary (it is too hard to marshal the child lists across the class loader boundary and the hibernate wrappers that track list changes are stripped). For crossing the CLB, it's simpler to just keep your entities without defined relations and manage the relationships manually (as Liferay does for all of it's many to many relationships).
Alex Man,修改在7 年前。

RE: Table mapping relationship in service builder

Junior Member 帖子: 70 加入日期: 16-2-8 最近的帖子
David H Nebinger:
SB is not going to handle this for you because of the extra id on the join table.


Is it possible if I am removing that id
thumbnail
David H Nebinger,修改在7 年前。

RE: Table mapping relationship in service builder

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Here's the comment from the liferay-service-builder_6_2_0.dtd file:

If the entity and mapping-table attributes are specified, then the Service
Builder will assume you are specifying a many to many relationship.

For example:

<column name="roles" type="Collection" entity="Role" mapping-table="Groups_Roles" />

The above column specifies that there will be a getter called
pojo.getRoles() that will return a collection. It will use a mapping table
called Groups_Roles to give a many to many relationship between groups and
roles.