Consider:
@Indexed
@Entity
public class TParent implements java.io.Serializable {
.....
private Set TChildSet = new HashSet(0);
In hibernate search, you can make a custom Bridge for this purpose.
Something along the lines of:
@FieldBridge(impl = com.myco.myapp.CollectionCountBridge.class)
@ContainedIn
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="TParent")
public Set<TChild> getTChildSet() {
return this.TChildSet;
}
With the custom bridge implementation:
public class CollectionCountBridge extends PaddedIntegerBridge {
@Override
public String objectToString(Object object) {
if (object == null || (!(object instanceof Collection))) {
return null;
}
Collection<?> coll = (Collection<?>) object;
return super.objectToString(coll.size());
}
}