Skip to content

Service Builder

Liferay’s code generator for database-driven applications (creates *LocalService and *ServiceImpl).

  • Automate CRUD operations for custom tables.
  • Handle SQL/JPA boilerplate.
Terminal window
blade create -t service-builder bookstore
bookstore/service.xml
<entity name="Book" local-service="true">
<column name="bookId" type="long" primary="true" />
<column name="title" type="String" />
<column name="author" type="String" />
</entity>

Run:

Terminal window
blade gw buildService

This generates:

  • BookLocalService (interface).
  • BookLocalServiceImpl (your custom logic).
// In a portlet or another module
@Reference
private BookLocalService _bookLocalService;
public void addBook(String title, String author) {
Book book = _bookLocalService.createBook(0L);
book.setTitle(title);
book.setAuthor(author);
_bookLocalService.addBook(book);
}
  • Custom Tables: Store application-specific data (e.g., “Book”, “Order”).
  • Legacy Data Migration: Map external databases to Liferay.