Foros de discusión

Foreign keys on service builder

Rui Maciel, modificado hace 11 años.

Foreign keys on service builder

Junior Member Mensajes: 36 Fecha de incorporación: 23/07/12 Mensajes recientes
Anybody knows how to deal with foreign keys in service builder?


I tried this solution:
<entity name="Entity1" table="entity1" local-service="true" remote-service="false">
        <column name="entity1Id" type="long" primary="true" />
	<column name="field1" type="String" />
        <column name="field2" type="String" />
		<!-- Relationships -->
 		<column name="entity1Id" type="Collection" entity="Entity2" mapping-key="entity1Id" />
 </entity>

<entity name="Entity2" table="entity2" local-service="true" remote-service="false">
        <column name="entity2Id" type="long" primary="true" />
        <column name="entity1Id" type="long" />
	<column name="fieldX" type="String" />
 </entity>

But the entity1Id from the entity2 table continues without being foreign key..

It's possible to manipulate the tables.sql file in order to add some foreign keys?

Many thanks in advance
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Foreign keys on service builder

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Service builder does not support foreign keys.

You must manage foreign keys manually.
Rui Maciel, modificado hace 11 años.

RE: Foreign keys on service builder

Junior Member Mensajes: 36 Fecha de incorporación: 23/07/12 Mensajes recientes
But i do that in the tables.sql file or directly in the (in my case) mySql workbench?
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Foreign keys on service builder

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Liferay (and Service Builder) do not support FKs at all. SB generates simple tables that have columns (and sometimes indexes). It will not generate code to handle, support, enforce, or check foreign key requirements.

The tables.sql file will be used to create the table, but only if it doesn't exist. It is also volatile in that each time you run service builder it will get overwritten.

If you really, really needed to, you could modify the table in the mysql workbench.
Rui Maciel, modificado hace 11 años.

RE: Foreign keys on service builder

Junior Member Mensajes: 36 Fecha de incorporación: 23/07/12 Mensajes recientes
Many Thanks, i really need to change them because besides the foreign key problem, i also need to modify in some cases the VARCHAR(75) default size to another size.
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Foreign keys on service builder

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
No, you change the portlet-model-hints.xml file and re-run service builder to do that.
Rui Maciel, modificado hace 11 años.

RE: Foreign keys on service builder

Junior Member Mensajes: 36 Fecha de incorporación: 23/07/12 Mensajes recientes
But the portlet-model-hints.xml file only has the entity types, it doesn't have the table types, how can i ensure the table columns have the size i want?
And you are saying that i use the model-hints.xml file to work with the column sizes or the foreign keys problem is corrected here too?
Sorry :S
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Foreign keys on service builder

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
It has the types and sizes. You can change the sizes here and they'll stick. Tables don't have types to worry about.

Liferay does not support foreign keys anywhere. Period.
Rui Maciel, modificado hace 11 años.

RE: Foreign keys on service builder

Junior Member Mensajes: 36 Fecha de incorporación: 23/07/12 Mensajes recientes
Thanks! =D