How to define an entity in Service Builder for existing tables

Posted on by Charalampos Chrysikopoulos

Recently we encounter a case, where the tables of an external database were "moved" as synonyms in the schema of the liferay db. This was made to eliminate the extra connections in the same database but on a different schema (liferay's service builder can't handle different schemas in the same database with one datasource. You have to define a new datasource as an external database).

So, having now the tables in the liferay db, we can defined the entities in the service.xml as normal entities. But this has a side effect: liferay will try to create the tables in case they don't exist. And if they are synonyms, liferay will throw an error and say that another object (the synonym) has the same name with the table that is about to create.

There is a workaround: you can create a fake datasource and define it in the entity in service.xml. This datasource can return the null value, so the service builder will think it is an external db and won't create any scripts for this entity. But because the datasource is null, the default datasource will be used.

This entry was posted in Liferay and tagged database, Liferay, service builder by Charalampos Chrysikopoulos