Fórum

Table mapping relationship in service builder

Alex Man, modificado 7 Anos atrás.

Table mapping relationship in service builder

Junior Member Postagens: 70 Data de Entrada: 08/02/16 Postagens Recentes
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, modificado 7 Anos atrás.

RE: Table mapping relationship in service builder

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
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, modificado 7 Anos atrás.

RE: Table mapping relationship in service builder

Junior Member Postagens: 70 Data de Entrada: 08/02/16 Postagens Recentes
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, modificado 7 Anos atrás.

RE: Table mapping relationship in service builder

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
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.