[hibernate-issues] [JIRA] (HSEARCH-3844) Exception: null: java.lang.NullPointerException when use simpleQueryString()

Yoann Rodière (JIRA) jira at hibernate.atlassian.net
Thu Feb 27 11:56:11 EST 2020


Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A58fa1ced-171a-4c00-97e8-5d70d442cc4b ) *commented* on HSEARCH-3844 ( https://hibernate.atlassian.net/browse/HSEARCH-3844?atlOrigin=eyJpIjoiNDIzNzIwMzMzZWZlNDI5Yjg1MzAxZTQ2NWM2MDFlZjIiLCJwIjoiaiJ9 )

Re: Exception: null: java.lang.NullPointerException when use simpleQueryString() ( https://hibernate.atlassian.net/browse/HSEARCH-3844?atlOrigin=eyJpIjoiNDIzNzIwMzMzZWZlNDI5Yjg1MzAxZTQ2NWM2MDFlZjIiLCJwIjoiaiJ9 )

You are mixing two approaches here, which may be the reason you're getting this exception.

*Step objects, like the one you're storing in the "select" and "sort" variables, are not meant to be passed around at all. For that, you should call toPredicate() / toSort() etc. and then you will get a SearchPredicate / SearchSort /etc. that you can safely pass around and even re-use.

Try this:

    if (searchFullText != null ) { select = scope.predicate().simpleQueryString() .field( "shoppingName" ) .matching(searchFullText) .defaultOperator(BooleanOperator.AND).toPredicate(); }

   else { select = scope.predicate().matchAll().toPredicate(); }

   SearchQuery<Assortment> query = session.search(scope)
   .where(select)
   .sort(sort).toQuery();

or this:

   
   SearchQuery<Assortment> query = session.search(scope)
   .where(f -> {
       if (searchFullText != null ) { return f.simpleQueryString() .field( "shoppingName" ) .matching(searchFullText) .defaultOperator(BooleanOperator.AND); }
       else { return f.matchAll(); }
   } )
   .sort( f -> ... ).toQuery();

( https://hibernate.atlassian.net/browse/HSEARCH-3844#add-comment?atlOrigin=eyJpIjoiNDIzNzIwMzMzZWZlNDI5Yjg1MzAxZTQ2NWM2MDFlZjIiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-3844#add-comment?atlOrigin=eyJpIjoiNDIzNzIwMzMzZWZlNDI5Yjg1MzAxZTQ2NWM2MDFlZjIiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:0fbe7c1 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200227/e8a9a67b/attachment.html 


More information about the hibernate-issues mailing list