-->
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: indexes not being created for @IndexedEmbedded fields
PostPosted: Tue Jul 07, 2009 4:13 pm 
Newbie

Joined: Thu Jun 25, 2009 9:10 am
Posts: 3
I'm having a problem creating the index for @IndexedEmbedded fields. I have an AuditRecord class(which is Inedexed) that contains a List of AuditRecordDetails (this is not Indexed). When I view the AuditRecord indexes via Luke, I see fields for the other columns, but not for the @IndexedEmbedded field. I would expect to see a field called auditRecordDetail.value
I am using Hibernate search 3.1.1.GA.

Code:

@Entity
@Table(name = "auditrecord")
@Indexed
public final class AuditRecordModel implements AuditRecord
{
   ...
   
    @OneToMany(mappedBy = "auditRecord", cascade = { CascadeType.ALL }, targetEntity = AuditRecordDetailModel.class)
    @ForeignKey(name = "FK_AUDITRCD_DETAIL")
    @IndexedEmbedded
    public List<AuditRecordDetail> getAuditRecordDetails()
    {
        return _auditRecordDetails;
    }
   
    @Override
    @Column(name = "initiator", nullable = false, length = 128)
    @Field(index = Index.TOKENIZED, store = Store.NO)
    public String getInitiator()
    {
        return _initiator;
    }
   
    ...
}

@Entity
@Table(name = "auditrecorddetail")
public final class AuditRecordDetailModel implements AuditRecordDetail
{
    ...

    @Column(name = "value", nullable = false)
    @Field(index = Index.TOKENIZED, store = Store.NO)
    public String getValue()
    {
        return _value;
    }
   
    ...
   
}


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Wed Jul 08, 2009 4:18 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm unsure if the use of targetEntity on an interface-type collection has been tested with Search.
Could you verify your same model works when using the implementation instead of the interface?

If that is the problem feel free to open a new issue on JIRA; as always including a TestCase or provide a patch will help a lot.

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


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Wed Jul 08, 2009 3:08 pm 
Newbie

Joined: Thu Jun 25, 2009 9:10 am
Posts: 3
Thank you for your response.

I modified my code to use the implementation instead of the interface and the indexes were created successfully. I also downloaded the Hibernate Search in Action example code and modified 2 classes in Chapter4 (Item.java and Actor.java) to implement interfaces and specified the implementation for the targetEntity. I was able to reproduce the same problem in this sample code as well.

I will open up a JIRA and include the Chapter4 test case. Could you point me in the right direction and let me know what hibernate class to look at so I can provide a patch?


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Wed Jul 08, 2009 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
thanks!
I'll give you some pointers, but please wait for Emmanuel or Hardy to confirm what I say (I'll ping them); also further discussion should continue on the dev-list, so that all developers can comment on this.

If you look into /hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
the method
Code:
private void processContainedIn(Object instance, List<LuceneWork> queue, PropertiesMetadata metadata, SearchFactoryImplementor searchFactoryImplementor) {
...
}
at DocumentBuilderContainedEntity.java
takes care of delegating the embedded field generation to the DocumentBuilder of the contained-in type;
the simple case is the last one (line 661) where it decides to delegate to the documentbuilder for the type
of the field itself.
There you should change it to read from the impl parameter of the JPA/Hibernate annotation, but there are some requirements:
A)should work also on the collections, not only field (Maps,Arrays,Collections)
B)Search should work also without those annotations being on classpath, so you should not reference directly to the annotation class but use reflection, like what was done for @Id, see the method
Code:
Annotation getIdAnnotation(XProperty member, InitContext context)
in DocumentBuilderIndexedEntity.java for an example: it checks for JPA presence and loads the annotation by reflection. In your case you will actually need to cast it to the class to read the options, but make sure you don't import it.
C)The "processContainedIn" method is used at runtime for each object added to the index, the final patch should make sure you read the metadata only once at startup.

Another useful pointer: Contributing to Hibernate Search

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


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Thu Jul 09, 2009 4:05 am 
Hibernate Team
Hibernate Team

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

Have you actually tried using the 'targetElement' parameter of the @IndexedEmbedded annotation?

--Hardy


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Thu Jul 09, 2009 4:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Ah... I'm sorry Lynn it appears I was totally wrong, I didn't remember this option Hardy told about.

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


Top
 Profile  
 
 Post subject: Re: indexes not being created for @IndexedEmbedded fields
PostPosted: Thu Jul 09, 2009 10:36 am 
Newbie

Joined: Thu Jun 25, 2009 9:10 am
Posts: 3
I added the the 'targetElement' parameter to the @IndexedEmbedded annotation and it resolved the problem. The indexes are now being created.

Thanks for your help!


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.