Hello,
We implemented a @ClassBridge(impl=OrderIndexer.class) to add some additional custom fields to an indexed object, Order.class. There are no fields annotated with @Field, nor are there any @IndexEmbedded fields on Order.class. This class does have some @OneToMany related entity collections that are marked Cascade.ALL.
When we save an Order for the first time, we notice via a breakpoint in OrderIndexer.set (the implementation of FieldBridge.set) that we re-enter this method several times. The number of times the set() method is called corresponds to the number of fields annotated with @OneToMany when the collections contain modified entities. If the OneToMany collections contain no modified entities, the ClassBridge is only called once.
Why would the presence of @OneToMany collections affect how many times the ClassBridge is called?
Note, each time set(String name, Object value, Document doc, LuceneOptions options) is called, the value (Order.class), has the same hashcode, but the Document is a new one.
Hibernate Versions:
hibernate-core-3.5.4-Final.jar
hibernate-search-3.2.1.Final.jar
Example code, shortened to relevant sections:
Order.class:
Code:
@Entity
@Indexed
@ClassBridge(impl=OrderIndexer.class)
public class Order implements Serializable {
@Id
@GeneratedValue
private Integer orderid;
@OneToMany(mappedBy="order", fetch=FetchType.LAZY, cascade={CascadeType.ALL})
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private List<OrderLedger> orderLedgers = new ArrayList<OrderLedger>(0);
}
OrderIndexer.class:
Code:
public class OrderIndexer implements FieldBridge {
public void set(String name, Object value, Document doc, LuceneOptions options) {
// called several times...
}
}
OrderLedger.class:
Code:
@Entity
public class OrderLedger implements Serializable {
@Id
@GeneratedValue
private Integer itemid;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="orderid")
private Order order;
}