Blogs

List Of Blogs > Liferay Finders

Liferay Finders

Alisha Fathima


Liferay Finders

Introduction : Finder methods retrieve entity objects from the database based on specified parameters. For each finder defined, Service Builder generates several methods to fetch, find, remove, and count entity instances based on the finder’s parameters.

 

To create Finder follow the steps

 

  1. We need to defined finder tag in service.xml file and this tag should be enclosed by entity tag.

 

Explanation:-

  • We have defined one element (finder) inside Register entity. This will create finder method for column firstName.
  • The value of return-type is Collection which means that the return type of finder method will be List.
  • If the method returns only one object or one record then we can specify as Object i.e. respective object we specified as entity.
  • The value of name attribute will be used to construct finder method name. We gave firstName so the generated finder method name will be findByfirstName ().
  • element Inside the element represents the column name.
  • The name attribute of element represents the name of the column. It should have the exact same name as ’s name attribute of which we want finder method.
  • After doing this just build your service and refresh your project

 

  1. On successful service build, this will generate a method findByfirstName() in com.cuapos.service.persistence.RegisterUtil.java

 

  1. To use this method we have to expose the finder method to our LocalServiceUtil class. Open “RegisterLocalServiceImpl” class and add the below code in it.

 

  1. Now build the services again, gradle refresh, this method will be added RegisterLocalServiceUtil.

 

  1. Call your finder like RegisterLocalServiceUtil.findByfirstName(“firstName”) from any where of your portlet

 

 

  1. Output : Retrieving List having identical firstName along with different lastName and id from database.

Fetching List having same firstName from database.


Post by

Alisha Fathima

Categories


Archive