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