-->
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.  [ 4 posts ] 
Author Message
 Post subject: Keeping an index up to date without @ContainedIn
PostPosted: Fri Aug 31, 2012 11:44 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

In some cases, you have a oneway ManyToOne Relation to an object that doesn't (shouldn't) have a return reference. See the example below.
When you update this Poll object, you want the containing index to be updated also. Is there a scenario for this that doesn't involve creating a reference in the Poll object to the Post object with @ContainedIn?

Arguably, one would like Hibernate Search to monitor changes for all the leaves that are handed to it through IndexedEmbedded automagically.

Code:
@Entity
@Table
@Indexed
public class Post{   
   
   @ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
   @JoinColumn(name="FK_PollId", nullable=true,updatable=false)
   @IndexedEmbedded
   public Poll getPoll() {
      return poll;
   }

}

@Entity
@Table
public class Poll {

   @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="poll",orphanRemoval=true)
   @IndexedEmbedded(prefix="question.")
   public List<Question> getQuestions() {
      return questions;
   }

}

@Entity
@Table
public class Question {

   @Column(name="voteCount")
   @Field(index=Index.NO,store=Store.YES)
   @org.hibernate.annotations.Index(name="idxPollCount")
   public int getCount() {
      return count;
   }
}



Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: Keeping an index up to date without @ContainedIn
PostPosted: Fri Aug 31, 2012 12:53 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
So, yes, you can add this to Poll

Code:
@OneToOne(optional=false,fetch=FetchType.LAZY,mappedBy="poll")
@ContainedIn
public Post getPost(){
   return post;
}


But as far as I'm concerned, Hibernate Search now forced me to tightly couple something that I don't want to tightly couple. But ok, it now works.

However, when I modify a Poll object, I see all of the other (some Lazy, some Extra Lazy because they never ever should be loaded as a whole) unchanged children of Post being loaded by Hibernate, presumably to recreate the entire index record, when only a single field changed. That's a performance killer and it puzzles me each and every time I see something like that happen (I got rid of classbridges alltogether for this very reason).

Any ideas (using Hsearch 4.1.1)?

Cheers,
Marc


Last edited by mschipperheyn on Fri Aug 31, 2012 5:00 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Keeping an index up to date without @ContainedIn
PostPosted: Fri Aug 31, 2012 1:42 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
When I debug this, I basically see Hibernate correctly identifying the dirty relationships and updating them.
However, when we hit Hibernate Search
PostTransactionWorkQueueSynchronization.beforeCompletion(84) | Processing Transaction's beforeCompletion() phase: org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization

Boom! Everything gets initialized, including all the non-dirty and extra lazy items. It's basically a full reindex instead of an update.

Really puzzling and it looks like incorrect behaviour. Any suggestions are appreciated.

Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: Keeping an index up to date without @ContainedIn
PostPosted: Mon Sep 03, 2012 9:03 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Arguably, one would like Hibernate Search to monitor changes for all the leaves that are handed to it through IndexedEmbedded automagically.

Arguably I would agree with you, that would be nice. But it's not implemented.

For other readers: we continue discussion on lazy loading in https://forum.hibernate.org/viewtopic.php?f=9&t=1023973

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


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