saperliu / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Check for null values in search params #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I struggled for a while to figure why I got the error:

Caused by: java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
    at java.util.regex.Matcher.reset(Matcher.java:291)
    at java.util.regex.Matcher.<init>(Matcher.java:211)
    at java.util.regex.Pattern.matcher(Pattern.java:888)
    at
com.trg.dao.BaseSearchProcessor.securityCheckProperty(BaseSearchProcessor.java:6
19)
    at com.trg.dao.BaseSearchProcessor.securityCheck(BaseSearchProcessor.java:583)
    at com.trg.dao.BaseSearchProcessor.generateQL(BaseSearchProcessor.java:86)
    at
com.trg.dao.hibernate.HibernateSearchProcessor.search(HibernateSearchProcessor.j
ava:73)
    at
com.trg.dao.hibernate.HibernateSearchProcessor.searchAndCount(HibernateSearchPro
cessor.java:144)
    at com.trg.dao.hibernate.BaseDAOImpl._searchAndCount(BaseDAOImpl.java:544)
    at
com.trg.dao.dao.standard.GenericDAOImpl.searchAndCount(GenericDAOImpl.java:106)

Eventually I figured out this is because I did not register my class with
hibernate.  oops!

(using version 4.1)

Original issue reported on code.google.com by ryan...@gmail.com on 27 Jan 2009 at 9:17

GoogleCodeExporter commented 9 years ago
actually not fixed with I add the class to hibernate... still sorting this one 
out.

It happens when I try to search for everything from a GenericDao:

    Search search = new Search();
    search.addSort( new Sort( sortProperty, !sortAsc ) );
    search.setFirstResult( query.getFrom() );
    search.setMaxResults( query.getCount() );

    SearchResult<T> res =_dao.searchAndCount( search );

Original comment by ryan...@gmail.com on 27 Jan 2009 at 9:23

GoogleCodeExporter commented 9 years ago
So, the problem came from adding a null sortProperty. adding:

    if( sortProperty != null ) {
      search.addSort( new Sort( sortProperty, !sortAsc ) );
    }

fixed things for me.  

Thought identical code worked for version 0.2...

Closing this issue is probbably fine.  Or throw a more descriptive error in:
securityCheck()

thanks
ryan

Original comment by ryan...@gmail.com on 27 Jan 2009 at 10:24

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I agree we should add a more descriptive error.

Original comment by dwolvert on 27 Jan 2009 at 10:35

GoogleCodeExporter commented 9 years ago
Robust null checking has been implemented in version 0.4.2 according to the 
following 
rules...

*The field list may not contain null elements. A Fetch with a null property 
returns 
the root entity of the search.
*Null fetches are ignored.
*Null sorts are ignored. A sort with a null property sorts on the root entity 
of the 
search.
*Null filters are ignored. Filters with a null property refer to the root 
entity of 
the search.

Original comment by dwolvert on 13 Mar 2009 at 4:19