-->
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.  [ 7 posts ] 
Author Message
 Post subject: FullTextQuery is returning List of nulls
PostPosted: Thu Dec 27, 2012 11:01 am 
Newbie

Joined: Mon Dec 24, 2012 6:32 am
Posts: 17
I have a country table which is mapped to the Country entity using JPA.I am trying to query it using FullTextQuery. However it is returning a List containing only null values. The table has 172 rows, the query return 174 nulls.
What could be the problem ?
Information :
I had done manual indexing using MassIndexer above this code but i removed it after executing it once.The indexes are getting set properly,as the files are getting created and they are 7Kb so obviously contain something. I am using Hibernate Search with JPA and I have used CDI to inject the entity manager
Other stuff : using eclipse, JBoss,maven and I have locally installed hibernate-search-orm-4.1.1.Final.
I am not getting any errors/warnings.
The country table has a composite key which is inherited from another entity. The composite key consists of id and date field.I have written a two way string bridge field and specified that in the base class. The code for that is at the bottom, I have ignored the date field temporarily for simplicity purpose.
Please Help,
THanks in Advance.

Code:
      if (searchString.isEmpty())
         return null;
      if (entityManager == null)
         throw new RuntimeException("Entity Manager Not initialised");
       FullTextEntityManager fullTextEntityManager = Search
            .getFullTextEntityManager(entityManager);
      
            final QueryBuilder queryBuilder = fullTextEntityManager
            .getSearchFactory().buildQueryBuilder()
            .forEntity(Country.class).get();
      org.apache.lucene.search.Query luceneQuery = queryBuilder.all().createQuery();
      javax.persistence.Query fullTextQuery = fullTextEntityManager
            .createFullTextQuery(luceneQuery);
      
      List<Country> list = fullTextQuery.getResultList();


CompositePKBridge:
Code:
public class CompositePKBridge implements TwoWayStringBridge {

   @Override
   public String objectToString(Object arg0) {
      CompositePK compositePK = (CompositePK)arg0;
      return compositePK.getId() + "";
   }

   @Override
   public Object stringToObject(String value) {
      CompositePK compositePK=new CompositePK();
      compositePK.setId(Long.parseLong(value));
      return compositePK;
   }
}

_________________
Sourabh Ghorpade


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Fri Dec 28, 2012 7:04 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you can not ignore the Date field: the stringToObject method must return the exact same primary key as was given to objectToString as these fields will be used to load the entities from the database.

To keep it simple you could try a projection query first:
http://docs.jboss.org/hibernate/search/4.2/reference/en-US/html_single/#projections

If you have it project a stored field you don't need to implement the stringToObject correctly, and should be able to play with real results.

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


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Fri Dec 28, 2012 11:22 pm 
Newbie

Joined: Mon Dec 24, 2012 6:32 am
Posts: 17
Hi Sanne,
Thanks for your fast reply. I have made the objectToString and stringToObject methods idempotent however they do not reflect the primary key of the database. Could that be an issue ?
I will try using projections and stored fields and get back to you.
Thanks again,

_________________
Sourabh Ghorpade


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Sun Dec 30, 2012 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi sourabh, let me know how that goes as I might not have understood your problem.
If it still doesn't work, can you simplify your case in a minimalist Maven project and share it so I can have a look?

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


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Thu Jan 03, 2013 12:39 am 
Newbie

Joined: Mon Dec 24, 2012 6:32 am
Posts: 17
Hi Sanne,
problem solved ! adding the date field as id to the bridge did the trick :-). Thanks a lot. I was stuck on the issue for a long time, your response really helped me break the barrier fast.
So what I understood from the issue was that the ID field should exactly match the table/view in the database(which is logical). Am i right ?
But can I add fields to the id ? e.g if the key in DB is x+y , can I make the key in Hibernate Search to x+y+z ?
Thanks again.

_________________
Sourabh Ghorpade


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Thu Jan 03, 2013 5:53 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
So what I understood from the issue was that the ID field should exactly match the table/view in the database(which is logical). Am i right ?

They are in fact of a different type: what you store in the index is a String, so you need to represent the database value as a String and be able to re-transform it back to the exact match of the original key. But you are free to encode / represent it as you wish.

Quote:
But can I add fields to the id ? e.g if the key in DB is x+y , can I make the key in Hibernate Search to x+y+z ?

Yes you can, but then if you want to make a query on the id field you will need to query for "x+y+z" so I'm not sure how useful it is.
The important thing is that you maintain this property:

Code:
CompositePKBridge bridge = ...
final Object pk = //any primary key instance
assert bridge.stringToObject( bridge.objectToString( pk ) ).equals( pk );
final String key = //any valid encoding of your keys
assert bridge.objectToString( bridge.stringToObject( key ) ).equals( key );

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


Top
 Profile  
 
 Post subject: Re: FullTextQuery is returning List of nulls
PostPosted: Thu Jan 03, 2013 9:18 am 
Newbie

Joined: Mon Dec 24, 2012 6:32 am
Posts: 17
hmm... so being idempotent is most important for the methods. Got it.
Can you also have a look at this

https://forum.hibernate.org/viewtopic.php?f=9&t=1025076&sid=a545af231767845392787f65c86c7145

Thanks a lot 4 your help,

_________________
Sourabh Ghorpade


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.