-->
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.  [ 5 posts ] 
Author Message
 Post subject: hibernate search problem w/ entity inheritance
PostPosted: Mon Dec 21, 2009 2:40 pm 
Newbie

Joined: Wed Dec 09, 2009 3:42 pm
Posts: 5
I am using hibernate-search 3.0.1.GA.

I am trying to create an index with entities that inherit off a base entity;

Here is the main entity I want to store the id in the index. It has many text items. The text item has two child classes one child has a varchar the other has a clob. I want to index the text for both of those child entities in the same index. I.E. when searching for text I want my search to return a docId if the text exists in either if my children classes/tables.
Code:
@Entity
@Indexed(index = "text")
@Table(name = "DOC")
public class Doc implements java.io.Serializable {
.
   private Set<TextItem> textItems = new HashSet<TextItem>(0);
.
.
   @Id
   @DocumentId
   @Column(name = "DOC_ID", unique = true, nullable = false, scale = 0)
   @GeneratedValue( strategy=GenerationType.SEQUENCE, generator="GS_DOC_GEN" )
   @SequenceGenerator( name="GS_DOC_GEN", sequenceName="GS_DOC", allocationSize=1 )
   public long getDocId() {
      return this.docId;
   }
.
.
   @IndexedEmbedded
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "doc", cascade = CascadeType.ALL)
   public Set<TextItem> getTextItems() {
      return this.textItems;
.
.
   }


TextItem entity (this is the parent class) This class does not have any search annotations, the children classes have them
Code:
Entity
@Table(name = "TEXTITEM")
@Inheritance(strategy=InheritanceType.JOINED)
public class TextItem implements java.io.Serializable {
.
.

.
.


Here is one of the children (both look the same except for type of text field)
Code:
@Entity
@Table(name="TEXTITEM_CHR_VALUE")
public class TextItemCharValue  extends TextItem {
.
.
    @Column(name="VALUE", nullable=false)
    @Field(index=Index.TOKENIZED)
    public String getValue() {
        return this.value;
    }
.
.


So I want to index the value field on my child table so I use the @Field. I am not sure if I need anything on the parent class (TextItem) as far as annotations, and I have the EmbeddedIndex annotation on the TextItems in the Doc entity.

I am not getting a field for value for this situation. If I have a @Field in the parent class a field gets created just fine but it seems like the @Field annotations are ignored in the children classes. How do I index off of DocID when the Doc entity contains a set of parent entities that do not have anything to store (the children have the data)?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: hibernate search problem w/ entity inheritance
PostPosted: Thu Aug 26, 2010 11:24 am 
Newbie

Joined: Tue Aug 24, 2010 1:49 pm
Posts: 4
Have you solved this? I'm having the same problem. Thx.


Top
 Profile  
 
 Post subject: Re: hibernate search problem w/ entity inheritance
PostPosted: Fri Sep 03, 2010 3:19 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
the current implementation uses a static mapping, so all documents are built as being of type "TextItem" which has no fields.
It's pretty easy to workaround this limitation using a ClassBridge defined on TextItem, or a fieldbridge on the getter.

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


Top
 Profile  
 
 Post subject: Re: hibernate search problem w/ entity inheritance
PostPosted: Fri Sep 03, 2010 3:26 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
found the reference: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-438

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


Top
 Profile  
 
 Post subject: Re: hibernate search problem w/ entity inheritance
PostPosted: Fri Sep 03, 2010 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that by reversing the query you can achieve what you want.

Code:
Query luceneQuery = parser.parse("value:hibernate AND doc.id:12");
Query query = fts.createQuery( luceneQuery, TextItem.class );

_________________
Emmanuel


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