I have two classes, monitoringExpression and reportTrigger, with a one-to-many relationship. Hibernate is attempting to persist duplicate reportTriggers from the collection held by the monitoringExpression class. The first insert into the reportTrigger collection works, but subsequent inserts fail with a unique constraint violation because hibernate tries to persist the same reportTrigger twice. This is quite similar to a known hibernate bug (
http://stackoverflow.com/questions/7903 ... collection); however, in this case, we are not using a lazy collection. Here is the relevant code:
MonitoringExpression.ClassCode:
@Audited
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MonitoringExpression extends GeneratedIdXmlObject{
private String name;
private DeterminantDefinition determinantDefinition;
private String valueExpression;
private String testExpression;
private String messageExpression;
private String messageSeverity;
private boolean setExitStatusWhenTrue;
protected SortedSet<MonitoringExpressionAttribute> attributes = new TreeSet<MonitoringExpressionAttribute>();
private String color;
private Set<ReportTrigger> reportTriggers = new HashSet<ReportTrigger>();
.
.
.
@OneToMany(mappedBy="monitoringExpression",orphanRemoval=true,cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@Sort(type=SortType.NATURAL)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public SortedSet<MonitoringExpressionAttribute> getAttributes() {
return attributes;
}
public void setAttributes(SortedSet<MonitoringExpressionAttribute> attributes) {
this.attributes = attributes;
}
ReportTrigger.ClassCode:
@Audited
@Table(name="ReportTrigger")
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ReportTrigger extends GeneratedIdXmlObject{
private String name;
private String description;
private TriggerableReport report;
private Frequency burstPeriodSize;
private String periodStartExpression;
private String periodEndExpression;
private Set<ReportTriggerParameterMapping> parameterMappings = new HashSet<ReportTriggerParameterMapping>();
private MonitoringExpression monitoringExpression;
@XmlIDREF
@ManyToOne
@Audited
@GraphProcessorOverride(process=false,recurse=false)
@NaturalId(mutable=true)
public TriggerableReport getReport() {
return report;
}
public void setReport(TriggerableReport report) {
this.report = report;
}
@Embedded
public Frequency getBurstPeriodSize() {
return burstPeriodSize;
}
public void setBurstPeriodSize(Frequency burstPeriodSize) {
this.burstPeriodSize = burstPeriodSize;
}
@Audited
@OneToMany(mappedBy="reportTrigger",orphanRemoval=true,cascade={CascadeType.ALL})
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public Set<ReportTriggerParameterMapping> getParameterMappings() {
return parameterMappings;
}
.
.
.
@XmlIDREF
@ManyToOne
@GraphProcessorOverride(process=false,recurse=false)
@NaturalId(mutable=true)
public MonitoringExpression getMonitoringExpression() {
return monitoringExpression;
}
public void setMonitoringExpression(MonitoringExpression monitoringExpression) {
this.monitoringExpression = monitoringExpression;
}
As far as I can tell, we're not doing anything out of the ordinary to the reportTrigger collection (and we obviously cannot be adding the same tigger twice to a set). Has anyone seen anything like this? Thanks
Hibernate 3.6.10
Java 8