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 your Java model to the entities you define automatically, giving you a facility for taking Java objects and persisting them. For the Guestbook application, two entities are created according to its service.xml: one for Guestbooks and one for Guestbook Entries.

Here’s a summary of the Guestbook entity information:

  • Name: Guestbook
  • Local service: yes
  • Remote service: yes

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

  • Name: GuestbookEntry
  • Local service: yes
  • Remote service: yes

Here’s how you define entities:

<entity name="Guestbook" uuid="true" local-service="true" remote-service="true">
</entity>

<entity name="GuestbookEntry" uuid="true" local-service="true" remote-service="true">
</entity>

The entity’s database table name includes the entity name prefixed with the namespace. The Guestbook example creates one database table named GW_Guestbook and another named GB_GuestbookEntry.

Setting Local Service (the local-service attribute) to true instructs Service Builder to generate 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 instructs Service Builder to generate remote interfaces for the service. 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 »
这篇文章有帮助吗?
1 人中有 0 人觉得有帮助