{"action":"created","issue":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/1185","repository_url":"https://api.github.com/repos/primefaces/primefaces","labels_url":"https://api.github.com/repos/primefaces/primefaces/issues/1185/labels{/name}","comments_url":"https://api.github.com/repos/primefaces/primefaces/issues/1185/comments","events_url":"https://api.github.com/repos/primefaces/primefaces/issues/1185/events","html_url":"https://github.com/primefaces/primefaces/issues/1185","id":136924532,"number":1185,"title":"Change rowCount on LazyDataModel to long","user":{"login":"javahippie","id":3889351,"avatar_url":"https://avatars.githubusercontent.com/u/3889351?v=3","gravatar_id":"","url":"https://api.github.com/users/javahippie","html_url":"https://github.com/javahippie","followers_url":"https://api.github.com/users/javahippie/followers","following_url":"https://api.github.com/users/javahippie/following{/other_user}","gists_url":"https://api.github.com/users/javahippie/gists{/gist_id}","starred_url":"https://api.github.com/users/javahippie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javahippie/subscriptions","organizations_url":"https://api.github.com/users/javahippie/orgs","repos_url":"https://api.github.com/users/javahippie/repos","events_url":"https://api.github.com/users/javahippie/events{/privacy}","received_events_url":"https://api.github.com/users/javahippie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-27T14:24:27Z","updated_at":"2016-04-25T14:52:54Z","closed_at":null,"body":"Hi,\r\n\r\ni tried to discuss this in the forums, but there was no reaction to my suggestion: http://forum.primefaces.org/viewtopic.php?f=3&t=43369\r\n\r\nIt will rarely be the case, that the rowcount of a table will exceed the range of int, and I think it would be bad practice to have a LazyDataModel and a pageable datatable on such a table. But we also know, that developers have limited control over these facts. \r\n\r\n**More important**, most database drivers and persistence frameworks (JPA first) will return a long primitive on 'count' methods. If we want to use LazyDataModel with these libraries, we have to cast every result to int. On one hand, this is an inconvenience for the developer, but also my opinion is that casting long to int is always a code smell, as you can never be sure it will work forever. It is dangerous (I know, this is very theoretical and might be really rare in 'real life').\r\n\r\nChanging the field from int to long should not be a breaking change, because it is a widening primitive conversion and will be performed implicitly. "},"comment":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/comments/214372809","html_url":"https://github.com/primefaces/primefaces/issues/1185#issuecomment-214372809","issue_url":"https://api.github.com/repos/primefaces/primefaces/issues/1185","id":214372809,"user":{"login":"diogo-cvs","id":13366729,"avatar_url":"https://avatars.githubusercontent.com/u/13366729?v=3","gravatar_id":"","url":"https://api.github.com/users/diogo-cvs","html_url":"https://github.com/diogo-cvs","followers_url":"https://api.github.com/users/diogo-cvs/followers","following_url":"https://api.github.com/users/diogo-cvs/following{/other_user}","gists_url":"https://api.github.com/users/diogo-cvs/gists{/gist_id}","starred_url":"https://api.github.com/users/diogo-cvs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diogo-cvs/subscriptions","organizations_url":"https://api.github.com/users/diogo-cvs/orgs","repos_url":"https://api.github.com/users/diogo-cvs/repos","events_url":"https://api.github.com/users/diogo-cvs/events{/privacy}","received_events_url":"https://api.github.com/users/diogo-cvs/received_events","type":"User","site_admin":false},"created_at":"2016-04-25T14:52:54Z","updated_at":"2016-04-25T14:52:54Z","body":"Warning to integrate with spring-date: rowCount should be long.\r\nCheck line 67:\r\n\r\n```\r\npackage br.eti.jscm.commons.web.model;\r\n\r\nimport br.eti.jscm.commons.AbstractService;\r\nimport br.eti.jscm.commons.exception.CommonsException;\r\nimport br.eti.jscm.commons.hibernate.JpaUtils;\r\nimport br.eti.jscm.commons.lang.MapUtils;\r\nimport org.apache.commons.lang.StringUtils;\r\nimport org.primefaces.model.LazyDataModel;\r\nimport org.primefaces.model.SortOrder;\r\nimport org.springframework.data.domain.Page;\r\nimport org.springframework.data.domain.PageRequest;\r\nimport org.springframework.data.domain.Pageable;\r\nimport org.springframework.data.domain.Sort;\r\n\r\nimport java.io.Serializable;\r\nimport java.lang.reflect.Method;\r\nimport java.util.HashMap;\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\n/**\r\n * Spring Lazy Data Model.\r\n * @author diogo.soares@jscm.eti.br\r\n * @since 1.0-SNAPSHOT\r\n */\r\npublic class SpringLazyDataModel<ENTITY extends Serializable> extends LazyDataModel<ENTITY> {\r\n\r\n    private AbstractService service;\r\n    private Page<ENTITY> result;\r\n    private String methodName = \"listar\";\r\n    private Class<Object>[] paramTypes;\r\n    private Map<String, Object> filters;\r\n\r\n    public SpringLazyDataModel(AbstractService service, String methodName, String[] filterNames, Object[] filterValues) {\r\n        this.service = service;\r\n        this.methodName = methodName;\r\n        this.paramTypes = new Class[]{Map.class, Pageable.class};\r\n        this.filters = MapUtils.toMap(filterNames, filterValues);\r\n    }\r\n\r\n    @Override\r\n    public Object getRowKey(ENTITY entity) {\r\n        return JpaUtils.getPrimaryKey(entity);\r\n    }\r\n\r\n    @Override\r\n    public ENTITY getRowData(String rowKey) {\r\n        return invokeConsultar(Long.parseLong(rowKey));\r\n    }\r\n\r\n    @Override\r\n    public List<ENTITY> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {\r\n        this.setPageSize(pageSize);\r\n        PageRequest request = null;\r\n        if (sortOrder == SortOrder.UNSORTED || StringUtils.isBlank(sortField)) {\r\n            request = new PageRequest(first / pageSize, pageSize);\r\n        } else {\r\n            request = new PageRequest(first / pageSize, pageSize,\r\n                sortOrder == SortOrder.ASCENDING ? Sort.Direction.ASC : Sort.Direction.DESC, sortField\r\n            );\r\n        }\r\n        Map<String, Object> map = new HashMap(0);\r\n        map.putAll(this.filters);\r\n        map.putAll(filters);\r\n        result = invokeListar(map, request);\r\n        //TODO https://github.com/primefaces/primefaces/issues/1185\r\n        this.setRowCount((int) result.getTotalElements());\r\n        return result.getContent();\r\n    }\r\n\r\n    private Page<ENTITY> invokeListar(Map<String, Object> map, PageRequest request) {\r\n        try {\r\n            Method method = service.getClass().getMethod(methodName, paramTypes);\r\n            Object page = method.invoke(service, new Object[] {map, request});\r\n            return (Page)page;\r\n        }\r\n        catch (Exception e) {\r\n            throw new CommonsException(e);\r\n        }\r\n    }\r\n\r\n    private ENTITY invokeConsultar(Long id) {\r\n        try {\r\n            Method method = service.getClass().getMethod(\"consultar\", new Class<?>[]{Long.class});\r\n            return (ENTITY) method.invoke(service, id);\r\n        } catch (Exception e) {\r\n            throw new CommonsException(e);\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void setRowIndex(int rowIndex) {\r\n        super.setRowIndex((rowIndex==-1||getPageSize()==0)?-1:rowIndex%getPageSize());\r\n    }\r\n\r\n}\r\n\r\n```"}}