I am learning Liferay and have been stuck in a place where I don't know what to do.
I will just brief out what I am doing.
Creating a Library Management System using service builder and have the following Code in Service.xml file.
<entity name="LMSBook" local-service="true" remote-service="false">
<!-- PK fields -->
<column name="bookId" type="long" primary="true" id-type="increment"/>
<!-- UI fields -->
<column name="bookTitle" type="String" />
<column name="author" type="String" />
<!-- Audit fields -->
<column name="dateAdded" type="Date" />
</entity>
The Service build was successful without any errors. Now I am using following code to display the data from the table.
See the java below code:
List <LMSBook> books = LMSBookLocalServiceUtil.getLMSBooks(0, -1);
if(books.isEmpty()) {
System.out.println("Empty");
} else {
//Some Code Here
}
Here the books value is always null. I don't know why and DB has 3 rows in it but still its returning null. When I retrieve single value I am able to retrieve but when it come to multiple values it just returning NULL.
I am using following java code for single value retrieval:
LMSBook book = LMSBookLocalServiceUtil.getLMSBook(1);
Please help me solve this problem.
There is an issue in your code part below:
List <LMSBook> books = LMSBookLocalServiceUtil.getLMSBooks(0, -1);
It says limit 0 to -1 which is not correct.
In order to get all records you should use below code:
List <LMSBook> books = LMSBookLocalServiceUtil.getLMSBooks(-1, -1);
If you use -1 as start and end, it will return all the records.