user3663709
user3663709

Reputation: 11

play framework 2.4 ebean [PersistenceException: Property [] not found on models.SearchContent]

Hi boyz hi girsl I have a problem. I have a code:

public static List createPosts(PagedList searchContents){

    List<Post> posts = new ArrayList<Post>();
    List<SearchContent> searchContentsList = new ArrayList<SearchContent>();
    searchContentsList = searchContents.getList();

PaggedList generator:

PagedList<SearchContent> list = Ebean.find(SearchContent.class)
                .setRawSql(rawSql)
                .findPagedList(pageNumber, resultsToPage);

And I have a exception:

[PersistenceException: Property [] not found on models.SearchContent]

In this line:

    searchContentsList = searchContents.getList();

Why do I get an error?

Upvotes: 1

Views: 1142

Answers (2)

Anant Khurana
Anant Khurana

Reputation: 249

I have a solution: your property name in raw query and Model should be same with database table.

Sample code:-

<code>

RawSql rawSql = RawSqlBuilder
                .parse("SELECT  distinct CASE WHEN PARENT_EQUIPMENT_NUMBER IS NULL THEN EQUIPMENT_NUMBER ELSE  PARENT_EQUIPMENT_NUMBER END AS PARENT_EQUIPMENT_NUMBER " +
                        "FROM TOOLS_DETAILS").create();

    Query<ToolsDetail> query = Ebean.find(ToolsDetail.class);

    ExpressionList<ToolsDetail> expressionList = query.setRawSql(rawSql).where();//ToolsDetail.find.where();

    if (StringUtils.isNotBlank(sortBy)) {
        if (StringUtils.isNotBlank(sortMode) && sortMode.equals("descending")) {
            expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"desc");

            //expressionList.orderBy().asc(sortBy);
        }else if (StringUtils.isNotBlank(sortMode) && sortMode.equals("ascending")) {

            expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"asc");
           // expressionList.orderBy().asc(sortBy);
        } else {
            expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"desc");

        }


    }
    if (StringUtils.isNotBlank(fullTextSearch)) {
        fullTextSearch = fullTextSearch.replaceAll("\\*","%");
        expressionList.disjunction()
                .ilike("customerSerialNumber", fullTextSearch)
                .ilike("organizationalReference", fullTextSearch)
                .ilike("costCentre", fullTextSearch)
                .ilike("inventoryKey", fullTextSearch)
                .ilike("toolType", fullTextSearch);
    }

    //add filters for date range
    String fromContractStartdate = Controller.request().getQueryString("fm_contract_start_date_from");
    String toContractStartdate = Controller.request().getQueryString("fm_contract_start_date_to");
    String fromContractEndtdate = Controller.request().getQueryString("fm_contract_end_date_from");
    String toContractEnddate = Controller.request().getQueryString("fm_contract_end_date_to");

    if(StringUtils.isNotBlank(fromContractStartdate) && StringUtils.isNotBlank(toContractStartdate))
    {

        Date fromSqlStartDate=new Date(AppUtils.convertStringToDate(fromContractStartdate).getTime());
        Date toSqlStartDate=new Date(AppUtils.convertStringToDate(toContractStartdate).getTime());
        expressionList.between("fmContractStartDate",fromSqlStartDate,toSqlStartDate);
    }if(StringUtils.isNotBlank(fromContractEndtdate) && StringUtils.isNotBlank(toContractEnddate))
    {
        Date fromSqlEndDate=new Date(AppUtils.convertStringToDate(fromContractEndtdate).getTime());
        Date toSqlEndDate=new Date(AppUtils.convertStringToDate(toContractEnddate).getTime());
        expressionList.between("fmContractEndDate",fromSqlEndDate,toSqlEndDate);
    }

    PagedList pagedList = ToolsQueryFilter.getFilter().applyFilters(expressionList).findPagedList(pageNo-1, pageSize);

    ToolsListCount toolsListCount = new ToolsListCount();
    toolsListCount.setList(pagedList.getList());
    toolsListCount.setCount(pagedList.getTotalRowCount());
    return toolsListCount;

Upvotes: 0

anand kumar
anand kumar

Reputation: 21

Its because Ebean performs some logic on select clause properties to get property name of the object. It converts it to camelCase by removing underscore. For eg. If we have "select myid from ..." then it will search for property with name "myid" but in you Model class you may have written the member variable name as "myId".

It will work fine if your query is like "select my_id from .." if your member variable name is myid.

Upvotes: 2

Related Questions