-->
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.  [ 8 posts ] 
Author Message
 Post subject: one/manytoMany mapping
PostPosted: Thu Jul 15, 2010 9:00 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi all,

i would like to know if there is a better way to map oneToMany or ManyToMany entities than using FieldBridge? I checked in the documentation without finding another solution!
(for example, I have got a class A which contains a list of B)

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Thu Jul 15, 2010 9:28 am 
Hibernate Team
Hibernate Team

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


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Thu Jul 15, 2010 11:27 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
hi Hardy,

Thanks for your quick answer :) I have already tried this solution but I do not know how to use it in a search:
Code:
SearchMapping mapping = new SearchMapping();
mappping
    .entity(ProductCatalog.class).indexed().indexName("catalog")
        .property("catalogId", ElementType.FIELD).documentId().name("id")
        .property("title", ElementType.METHOD).field()
            .index(Index.TOKENIZED).store(Store.NO)
        .property("description", ElementType.METHOD).field().name("desc")
            .index(Index.TOKENIZED).store(Store.NO)
        .property("items", ElementType.METHOD).indexEmbedded()

    .entity(ItemImpl.class).indexed().indexName("item")
        .property("itemId", ElementType.FIELD).documentId().name("id")
        .property("name", ElementType.METHOD).field().name("itemName")

I am able to retrieve ProductCatalog using id, title ad description but not using embedded index. So what is the syntax to do it? (items.itemName ?)

Thanks

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Thu Jul 15, 2010 2:16 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
First of all your mapping is incorrect for doing index embedded. Please refer to the online documentation. When you have the index embedded mapped correctly the synax for the field you need will be something like this

[code]
indexEntity.embeddedEntites.name
[\Code]

Amin


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Fri Jul 16, 2010 4:49 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi Amin,

What is wrong with my mapping? Regarding to the online documentation (http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-mapping.html point 4.4.6) it seems to be correct but I should miss something but I do not know what!

Cannot I index an embedded index? (I can do it using a custom FieldBridge)

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Fri Jul 16, 2010 8:48 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Apologies! I wrote the reply while on the train and couldn't see indexEmbedded mapping. Let me ask you a question, what is the result that you will be returning product or items or both? If you want to search for index embedded objects then your query should be like

Code:
items.name


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Mon Jul 19, 2010 3:50 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi,
I finally found the problem :). The mapping is good but not my class implementation.
That what I used:
Code:
public class ProductCatalog {
...
  private List<Item> items;
...
  public List<Item> getItems() {
    return items;
  }
...
}

Code:
public interface Item {
...
  String getName();
...
}


It works when change Item by ItemImpl in ProductCatalog
- on the field, getter and setter if i keep the mapping above)
- on the field only if I change the mapping by .property("items", ElementType.FIELD).indexEmbedded())

As I would like to use the second option in my project (in my real case the field name is in the parent class of ItemImpl), I would like to know when the bug of inheritance (HSEARCH-550 and/or HSEARCH-551) using Programmatic API will be solved? (next maintenance version or next new version?)
Thanks in advance! :)

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: one/manytoMany mapping
PostPosted: Tue Aug 03, 2010 1:32 pm 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi all,

I found a workaround when using the programmatic API, a field or a method defined in a parent Class cannot be mapped. You have to map the parent class as well in your search mapping.

Example:
Code:
class ProductCatalog {
...
  protected List<ItemImpl> items;
...

  public List<Item> getItems()
...
}

Code:
class ProductCatalogImpl extends ProductCatalog {
...
  long catalogId;
  String title;
  ...
}

The working mapping is:
Code:
SearchMapping mapping = new SearchMapping();
mappping
    .entity(ProductCatalogImpl.class).indexed().indexName("catalog")
        .property("catalogId", ElementType.FIELD).documentId().name("id")
        .property("title", ElementType.METHOD).field()
            .index(Index.TOKENIZED).store(Store.NO)
        .property("description", ElementType.METHOD).field().name("desc")
            .index(Index.TOKENIZED).store(Store.NO)
     .entity(ProductCatalog.class).indexed()
        .property("items", ElementType.FIELD).indexEmbedded()
    .entity(ItemImpl.class).indexed().indexName("item")
        .property("itemId", ElementType.FIELD).documentId().name("id")
        .property("name", ElementType.METHOD).field().name("itemName")

instead of
Code:
SearchMapping mapping = new SearchMapping();
mappping
    .entity(ProductCatalogImpl.class).indexed().indexName("catalog")
        .property("catalogId", ElementType.FIELD).documentId().name("id")
        .property("title", ElementType.METHOD).field()
            .index(Index.TOKENIZED).store(Store.NO)
        .property("description", ElementType.METHOD).field().name("desc")
            .index(Index.TOKENIZED).store(Store.NO)
       .property("items", ElementType.FIELD).indexEmbedded()
    .entity(ItemImpl.class).indexed().indexName("item")
        .property("itemId", ElementType.FIELD).documentId().name("id")
        .property("name", ElementType.METHOD).field().name("itemName")

Looking hibernate search source code, I found in org.hibernate.search.impl.MappingModelMetadataProvider.MappingModelAnnotationReader when using the constructor: public MappingModelAnnotationReader(SearchMapping mapping, MetadataProvider delegate, AnnotatedElement el), if the annotated element is a field or a method, the declaring class is used to set the entityType instead of the mapped class (in my case : with the mapping which not work, for the field item, the entityType is ProductCatalog instead of ProductCatalogImpl).

Is it a good practice to index the class hierarchy? What about performance between a class and a class hierarchy? Thanks in advance

Regards,
Matti


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