-->
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.  [ 3 posts ] 
Author Message
 Post subject: How does @ContainedIn work exactly
PostPosted: Wed Mar 27, 2013 1:14 pm 
Pro
Pro

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

I'm curious in some aspects of @ContainedIn in terms of when it should or would be expected to trigger a database read.

E.g.

Code:
public class NetworkUser{
   private NetworkUserId pk;
   private Usor user;

   @EmbeddedId
   @DocumentId(name="id")
   @FieldBridge(impl = NetworkUserIdBridge.class)
   public NetworkUserId getPk() {
      return pk;
   }

   @MapsId(value = "userId")
   @ManyToOne(fetch=FetchType.LAZY,optional=false)
   @JoinColumn(name="userId",referencedColumnName="userId",nullable=false,updatable=false)
   @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.USER)
   @IndexedEmbedded(includePaths={"id","screenName"})
   @ContainedIn
   public User getUser()


In the case above, does NetworkUser get reindexed when:
1. The user is saved regardless if something changed in the User object
2. The user is saved with a changed screenName
3. The user is saved with some changed value other than screenName
Code:
public class NetworkUser{
   private NetworkUserId pk;
   private Usor user;

   @EmbeddedId
   @DocumentId(name="id")
   @FieldBridge(impl = NetworkUserIdBridge.class)
   public NetworkUserId getPk() {
      return pk;
   }
   @MapsId(value = "userId")
   @ManyToOne(fetch=FetchType.LAZY,optional=false)
   @JoinColumn(name="userId",referencedColumnName="userId",nullable=false,updatable=false)
   @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.USER)
   @IndexedEmbedded(includePaths={"id"})
   public User getUser()


In the case above, does NetworkUser get reindexed when:
1. The user is saved regardless of what changed in the user object
2. The user is saved with some changed value
3. The NetworkUser is saved with an updated value (since the user.id value is available from the NetworkUserId, a reload of User would be superfluous)
If so, would it makes sense to put @IndexedEmbedded(includePaths={"user.id"}) on getPk()? Since this value is immutable.
If so, and you do want to keep track of the user.screenName as an indexed value, would it make sense to put @IndexedEmbedded on getPk for user.id and on getUser for user.screenName, in order to minimize database reads?

It's kind of a how does it work question, but sometimes the exact details of when database reads should be generated are not clear to me and it would be nice to know the theoretical basis of that decision.

Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: How does @ContainedIn work exactly
PostPosted: Thu Mar 28, 2013 11:19 am 
Beginner
Beginner

Joined: Mon Apr 11, 2011 7:56 am
Posts: 38
Hi Marc,

AFAIK the @ContainedIn anno signals hibernate search to know that the instance that owns the property/field on which you put the annotation ('NetworkUser' in this case) is contained in the object(s) denoted by the annotated property/field (the 'User' instances).

For this example, Hibernate will force a reindex for User objects under the @ContainedIn anno when there are dirty (indexed) properties in the NetworkUser instance.


So I think you need to move the ContainedIn annotation to the other side of the relation, for example on a property User.getNetworkuser(). This way a NetworkUser instance returned by User.getNetworkuser() will be reindexed when there is a change to a searchable property of the User instance.


Top
 Profile  
 
 Post subject: Re: How does @ContainedIn work exactly
PostPosted: Fri Mar 29, 2013 1:15 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
You're right about that. I changed some stuff around and forgot to update that.


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