Hi all.
I have the following (piece of) model:
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name="text")
public class Text implements Serializable {
protected Set<Subtext> subtexts = new HashSet<Subtext>();
@OneToMany(mappedBy="text")
@Cascade(value = {CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE_ORPHAN })
private Set<Subtext> getSubtexts() {
return subtexts;
}
public void setSubtexts(Set<Subtext> subtexts) {
this.subtexts = subtexts;
}
}
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name="subtext")
public class Subtext implements Serializable {
private Text text = null;
@ManyToOne
@JoinColumn(name="text_uuid")
@NotNull
public Text getText() {
return text;
}
public void setText(Text text) {
this.text = text;
}
}
I use an interceptor to validate some fields. When I persist a Text objects with any Subtext object related to (Text.subtexts), the interceptor first catch Text entity, and then Subtext entity.
I need to update a date in Text when a Subtext is modified. I do that in the interceptor, but it does not work due to when Subtext is intercepted, Text yet has been processed and it is not intercepted again, even if my
onFlushDirty method returns true.
Note that:
- if I load a Subtext from DB and I modify it, the interceptor detects, in this order, the Subtext update and the Text update (I insist, in this order)
- but, if I load a Text from DB and I modify one of its Subtexts, then the interception order is: first Text, then Subtext.
In general, I need:
to be able to raise an entity interception within an interceptor's method (for a different entity).
to determine the interception order.
Any idea?