oo

Defining Entities

Entities are the heart and soul of a service. They represent the map between the model objects in Java and your database fields and tables. Service Builder automatically maps your Java model to the entities you define, giving you a facility for persisting Java objects. Consider the Y7G4 sample project found in Generating Model, Persistence, and Service Code. Here’s the summary of the entity:

  • Name: Y7G4Entry
  • Local service: yes
  • Remote service: no

Here’s how you define entities:

<entity local-service="true" name="Y7G4Entry" remote-service="false">
</entity>

The entity’s database table name includes the entity name prefixed with the namespace. The Y7G4 example creates one database table named Y7G4_Y7G4Entry.

Setting Local Service (the local-service attribute) to true generates local interfaces for the entity’s services. Local services can only be invoked from the Liferay server on which they’re deployed.

Setting Remote Service (the remote-service attribute) to true generates JSON-based remote interfaces for the service. These are not REST services; for that, you should use REST Builder. You can build a fully-functional application without generating remote services by setting your entity local services to true and remote services to false. If, however, you want to enable remote access to your application’s services, set both local service and remote service to true.

tip

If you have an existing Data Access Object (DAO) service for an entity built using some other framework such as JPA, you can set local service to false and remote service to true so that the methods of your remote -Impl class can call the methods of your existing DAO. This makes it easy to integrate with Liferay’s permission-checking system and provides access to the web service APIs generated by Service Builder. This is a very handy, powerful, and often used feature of Liferay.