-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: QueryBuilder bombs on null String
PostPosted: Thu Dec 22, 2011 8:44 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I have query like so
Code:
public class Item{
   @Field(index=Index.UN_TOKENIZED,store=Store.YES)
   @Column(length=255)
   public String getUrl() {
      return url;
   }
}

QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder()
            .forEntity(Item.class).get();
Query q = sj.must(qb.keyword().onField("url").matching(item.getUrl())
               .createQuery());


This bombs if item.getUrl() is null. I get the message

Code:
org.hibernate.search.SearchException: Search parameter on field url could not be converted. Are the parameter and the field of the same type?Alternatively, apply the ignoreFieldBridge() option to pass String parameters
   at org.hibernate.search.query.dsl.impl.Helper.getAllTermsFromText(Helper.java:78)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.getAllTermsFromText(ConnectedMultiFieldsTermQueryBuilder.java:173)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:98)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:73)


Why? Should I protect Hibernate against potential nulls? That would not make sense.

If I add the suggested ignoreFieldBridge, I get

Code:
org.hibernate.search.SearchException: Unable to search for null token on field url if field bridge is ignored.
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.buildSearchTerm(ConnectedMultiFieldsTermQueryBuilder.java:123)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:92)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:73)


Top
 Profile  
 
 Post subject: Re: QueryBuilder bombs on null String
PostPosted: Wed Jan 11, 2012 6:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Quote:
Why? Should I protect Hibernate against potential nulls? That would not make sense.


Why does it not make sense? null is normally not a valid search term. What would you expect?

--Hardy


Top
 Profile  
 
 Post subject: Re: QueryBuilder bombs on null String
PostPosted: Tue Jan 17, 2012 9:16 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I guess I would expect an ignore.


Top
 Profile  
 
 Post subject: Re: QueryBuilder bombs on null String
PostPosted: Tue Jan 17, 2012 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Marc,
sorry, I disagree. If it's an invalid term we should throw IllegalArgumentException at least, or SearchException like we do. This is generally useful as it helps spotting errors early, and most Java SE APIs do so as well so it's what an average Java developer would expect.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: QueryBuilder bombs on null String
PostPosted: Tue Jan 17, 2012 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Right, an exception seems to be the right thing. null is just not a valid search term.

--Hardy


Top
 Profile  
 
 Post subject: Re: QueryBuilder bombs on null String
PostPosted: Tue Jan 31, 2012 3:06 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I understand that. Given the fluid approach of chaining methods in the API, I would prefer ignoring nulls as opposed to working with MustJunctions etc but I see the point.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.