I am not able to segment data coming from repository in pages. Currently List
coming from repository has 14 elements. When I try to segment it with size
5 on each page, the code does not work. It throws exception (mentioned below).
JPA Repository method with native query
@Query(value= "select date(start_date) as DATEE, sum(case when subscription_from in ('IVR','SMS') and remarks like '%Change Song%' then 1 else 0 end) as song_change from subscription group by date(start_date) \n#pageable\n",nativeQuery=true)
Page<Object[]> getSongChangeCount2(Pageable page);
REST Template calling repository
@Override
public SongChangeCountView getSongChangeCount(int pageNo) {
logger.info("getAllCrbtData method:----------------");
RestTemplate restTemplate = new RestTemplate();
String ROOT_URI = IPADDRESS + "songChangeCounts?page=" + pageNo
+ "&size=5"; // here the total size coming is 14. when I change size to more than 14.. code works. but less than 14 it does not work. why so?
ResponseEntity<SongChangeCountView> response = restTemplate
.getForEntity(ROOT_URI, SongChangeCountView.class);
SongChangeCountView songChangeCountView = (SongChangeCountView) response
.getBody();
return songChangeCountView;
}
in above code when I change url with size to 5 (which is less than the maximum list size), the code throws below exception.
Exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group) from subscription group by date(start_date)
#pageable' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) ~[mysql-connector-java-5.1.6.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:381) ~[mysql-connector-java-5.1.6.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) ~[mysql-connector-java-5.1.6.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) ~[mysql-connector-java-5.1.6.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) ~[mysql-connector-java-5.1.6.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) ~[mysql-connector-java-5.1.6.jar:na]
What is this exception telling about? What should be the appropriate way to resolve this issue.?