liferay-6.1 - Implement own service

liferay-6

Solution

You would first declare this as a "finder" element in the `service.xml` within the entity you defined.

e.g.

<finder name="Name" return-type="Student">
    <finder-column name="name" />
</finder>

The `return-type` could also be `Collection` if wanting a `List<Student>` as the return type, if name is not unique.

<finder name="Name" return-type="Collection">
    <finder-column name="name" />
</finder>

You can also state a comparison operator for the column:

<finder name="NotName" return-type="Collection">
    <finder-column name="name" comparator="!=" />
</finder>

A finder can actually declare a unique index as well to be generated on this relation (will be applied to the DB table) by specifying the `unique="true"` attribute on the finder:

<finder name="Name" return-type="Student" unique="true">
    <finder-column name="name" />
</finder>

With this definition and after re-runing `ant build-service` the `studentPersistence` will contain new methods using the name of the finder found in the xml element appended with a prefix: countBy, findBy, fetchBy, removeBy, etc.

Finally, your serice method would only need to contain the following (based on the above):

public Student getStudentByName(String name) throws SystemException {
    return studentPersistence.findByName(name);
}

HTH

Problem

Hey I have create my own service.xml with student. Now o want to add my own searchByName method for student. can you please explain me what to write in StudentLocalServiceImpl. ``` public class StudentLocalServiceImpl extends StudentLocalServiceBaseImpl { /* * NOTE FOR DEVELOPERS: * */ public List<Student> getAll() throws SystemException { return studentPersistence.findAll(); } public Student getStudentByName(String name) { return studentPersistence. } ``` // I have created one method getAll. I need help for the another one. Thanks in Advance.

Original source