LRP-614 practice question 21 of 25

To map a Service Builder entity to an existing database table in service.xml the entity name must match the database table name.

Full set: 144 questions
Answer options
A: True
B: False
Correct Answer:
FALSE
Explanation

The statement is false. While Service Builder, by default, generates a database table name based on the entity name (e.g., entity Foo maps to table yourpluginFoo), it is not a mandatory requirement for the names to match. The service.xml DTD provides a table attribute within the tag specifically for this purpose. By using the table attribute, a developer can explicitly map an entity to a database table with a different name. This feature is essential for integrating with legacy databases or pre-existing tables that do not follow Liferay's naming conventions. For example, to map an entity named LegacyUser to an existing database table called USERS, the service.xml entry would be:

Why Incorrect

The "True" option is incorrect because it presents a strict limitation that does not exist. The presence of the table attribute in the service.xml DTD provides a direct mechanism to override the default naming convention, making the matching of entity and table names optional, not mandatory.

References

1. Liferay Portal 6.2 Developer's Guide, Chapter 5: Service Builder, Section: Defining the Object-Relational Map. This section details the structure of the service.xml file. It explains that the element has an optional table attribute that specifies the name of the database table to which the entity is mapped. If this attribute is not specified, the table name defaults to the entity's name, prefixed by the namespace. This confirms the mapping is configurable and not fixed.

2. Official Liferay Service Builder DTD (liferay-service-builder620.dtd). The Document Type Definition file for Service Builder in Liferay 6.2 explicitly defines the attributes for the element. The definition for the table attribute is . The #IMPLIED keyword signifies that the attribute is optional, directly refuting the claim that the entity name must match the table name.

3. Liferay in Action (Manning Publications), Chapter 4: Using Liferay's Service Builder, Section 4.2.1: Defining entities. This peer-reviewed book, while not official vendor documentation, is a widely respected academic-level resource on Liferay development. It describes the service.xml file and its elements, explicitly mentioning the table attribute as the mechanism to map an entity to a table with a different name, particularly for legacy database integration. (Note: While this is a high-quality source, official documentation like the DTD is the primary authority).

Scroll to Top