-->
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.  [ 2 posts ] 
Author Message
 Post subject: Projection on ManyToMany fields always returns null
PostPosted: Wed Feb 18, 2009 1:03 pm 
Newbie

Joined: Wed Feb 18, 2009 9:55 am
Posts: 2
Hi,

I'm trying to search in an index which as ManyToMany relations stored inside the index. Now I'm trying to get the value of the field by setting a projection on the query but I always get NULL values for all the ManyToMany fields! I already looked in to the index by using Luke and everything is fine. Even Luke gets the data for the fields and shows them...

So more precise:

Hibernate version: 3.3.1.GA
Hibernate Search version: 3.1.0GA
Hibernate Annotations version: 3.4.0GA
Hibernate Entitymanager version: 3.4.0GA
all retrieved by maven.

Mapping documents:
Document.class
Code:
@Indexed(index = "documents")
@Entity
@Table(name = "Documents", catalog = "vifachemPortal")
@AnalyzerDef(name = "fulltextanalyzer",
      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
      filters = {   
         @TokenFilterDef(factory = LowerCaseFilterFactory.class),
         @TokenFilterDef(factory = StopFilterFactory.class, params = {
                @Parameter(name="words", value= "de/l3s/vifachem/db/test/stoplist.txt" ),
                @Parameter(name="ignoreCase", value="true") }),
            @TokenFilterDef(factory = EnglishPorterFilterFactory.class) })
public class Documents implements java.io.Serializable {

...

   @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinTable(name = "DocumentsToKeywords", catalog = "vifachemPortal", joinColumns = { @JoinColumn(name = "id_doc", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_key", nullable = false, updatable = false) })
   @IndexedEmbedded
   public Set<Keywords> getKeywordses() {
      return this.keywordses;
   }

...
}


Keywords.class
Code:
@Entity
@Table(name = "Keywords", catalog = "vifachemPortal")
public class Keywords implements java.io.Serializable {
...
   @Column(name = "keyword", nullable = false, length = 200)
   @Field(index=Index.UN_TOKENIZED, store=Store.YES)
     public String getKeyword() {
      return this.keyword;
   }

   @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinTable(name = "DocumentsToKeywords", catalog = "vifachemPortal", joinColumns = { @JoinColumn(name = "id_key", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_doc", nullable = false, updatable = false) })
   @ContainedIn
   public Set<Documents> getDocumentses() {
      return this.documentses;
   }

...
}


Let's search:
Code:
      DAOFactory daoFactory = DAOFactory.instance(DAOFactory.HIBERNATE);
      DocumentsDAO ddao = daoFactory.getDocumentsDAO();
      EntityManager em = ddao.getEntityManager();
      FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
      
      String[] queryFields = new String[]{"title", "abstract"};
      Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer(Documents.class);
      MultiFieldQueryParser parser = new MultiFieldQueryParser(queryFields, analyzer);
      org.apache.lucene.search.Query query = parser.parse( "synthesis" );

      FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery(query, Documents.class);
      hibQuery.setProjection( FullTextQuery.SCORE, "title", "keywordses.keyword", FullTextQuery.THIS);
      List<Object[]> results = hibQuery.getResultList();
      
      for(Object[] result : results) {
         float score = (Float)result[0];
         String title = (String) result[1];
         String keywords = (String) result[2];
         Documents doc = (Documents) result[3];
         
         System.out.println(score + ": " + title + "\n" + keywords);
         System.out.println("\n");
      }



Name and version of the database you are using:
MySQL 5.0.45

Here keywords is alwys NULL! So if there are any suggestions, you are really welcome!!!!

-- Sushi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 9:21 am 
Hibernate Team
Hibernate Team

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

if you read the online documentation about projections you will find that:

Quote:
projection does not work on collections or maps which are indexed via @IndexedEmbedded


Think about it. In your example you are casting 'keywordses.keyword' to a single string, but really there could be many.

--Hardy


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