Defining Service 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 maps the entities you define automatically, giving you a facility for taking Java objects and persisting them. For the Bookmarks application, two entities are created according to its service.xml –one for bookmark entries and one for bookmark folders.

Here’s a summary of the BookmarksEntry entity information:

  • Name: BookmarksEntry
  • Local service: yes
  • Remote service: yes

And here’s what is used for the BookmarksFolder entity:

  • Name: BookmarksFolder
  • Local service: yes
  • Remote service: yes

Here are steps to create entities using Liferay Dev Studio DXP:

  1. In the outline on the left side of the service.xml editor in Overview mode, select the Entities node under the Service Builder node. In the main part of the view, notice that the Entities table is empty.

  2. Create an entity by clicking on the Add Entity icon (Add) to the right of the table.

  3. Name your entity and mark whether to generate local and remote services for it.

Add as many entities as you need.

Figure 1: Adding service entities in your service.xml file is easy with Liferay Dev Studio DXPs Overview mode.

Figure 1: Adding service entities in your `service.xml` file is easy with Liferay Dev Studio DXP's *Overview* mode.

The entity’s database table name includes the entity name prefixed with the namespace. The Bookmarks example creates one database table named Bookmarks_BookmarksEntry and another named Bookmarks_BookmarksFolder.

Setting Local Service (the local-service attribute) to true instructs Service Builder to generate local interfaces for the entity’s services. Local services are set to false by default. Local services can only be invoked from the Liferay server on which they’re deployed.

Setting Remote Service (the remote-service attribute) to true instructs Service Builder to generate remote interfaces for the service. Local services are set to true by default. You can build a fully-functional application without generating remote services. In that case, you could set 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.

Now that you’ve seen how to create your application’s entities, you’ll learn how to describe their attributes using entity columns.

« Defining Global Service InformationDefining the Columns (Attributes) for Each Service Entity »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0