-->
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: Hiberante Search and IndexedEmbedded collection
PostPosted: Fri Sep 16, 2011 6:21 am 
Newbie

Joined: Tue Feb 08, 2011 10:05 am
Posts: 13
Bean Parent has a collection of Child that should be indexted. To do so I have to define property childs (@OneToMany) and mark it as @IndexedEmbedded. The problem is I do not need property childs any other time except indexing. So I don't want define it at bean because it make structure much more complicated

How can I solve my problem better way?


Top
 Profile  
 
 Post subject: Re: Hiberante Search and IndexedEmbedded collection
PostPosted: Fri Sep 16, 2011 8:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Can you provide an example? And why do you not need the Child entities? Are they not part of your model? Maybe you could map then as lazy. They will be populated initially, but if you retrieve instances later on this collection won't be loaded (unless accessed).

--Hardy


Top
 Profile  
 
 Post subject: Re: Hiberante Search and IndexedEmbedded collection
PostPosted: Fri Sep 16, 2011 9:54 am 
Newbie

Joined: Tue Feb 08, 2011 10:05 am
Posts: 13
The problem is: the following code doesn't make correct index
Code:
child.setParent(parent)
. To get correct index I have to make
Code:
parent.addChild(child)
. I think it is not good if I only want correct Lucene index

I think I solved my problem by using Interceptors and custom FieldBridges. At save/delete time of child I execute
Code:
fullTextSession.index(child.getParent())
. Parent has property "luceneChilds" which returns "this". FieldBridge of property "luceneChilds" collects all childs and creates Lucene fields =)


Top
 Profile  
 
 Post subject: Re: Hiberante Search and IndexedEmbedded collection
PostPosted: Fri Sep 16, 2011 10:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
fedotxxl wrote:
The problem is: the following code doesn't make correct index
Code:
child.setParent(parent)
. To get correct index I have to make
Code:
parent.addChild(child)
. I think it is not good if I only want correct Lucene index

I don't understand why it is bad to have a bi-directional relation. Is it not a good thing that you can get from parents to children and vice versa. If you use lazy loading properly it is just a win at no almost no cost. And sure, if you have a bidirectional relation you have to set both ends.

I think I solved my problem by using Interceptors and custom FieldBridges. At save/delete time of child I execute
Code:
fullTextSession.index(child.getParent())
. Parent has property "luceneChilds" which returns "this". FieldBridge of property "luceneChilds" collects all childs and creates Lucene fields =)[/quote]

That's seems to be an awful lot of work and customization for something which could be very easy. A custom field bridge could of course solve your problem. However, I am wondering what luceneChilds really is? In the end you need to navigate from parent to child. Also, how do you collect the children in the bridge? If you are running another query what do you gain really?

--Hardy


Top
 Profile  
 
 Post subject: Re: Hiberante Search and IndexedEmbedded collection
PostPosted: Fri Sep 16, 2011 10:52 am 
Newbie

Joined: Tue Feb 08, 2011 10:05 am
Posts: 13
May be you are right...
But now I don't need bi-directional relation to make correct Lucene index. I have dao method getAllChilds(parent) and calls it only at necesary time. Now I have more understanding what's happening

Quote:
Also, how do you collect the children in the bridge? If you are running another query what do you gain really?
I'm getting dao object by static method


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.