you could add the annotation
@Cascade ({@Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN}) })
to your @OneToMany and @ManyToOne attributes and then simply do :
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private Short id;
@Column(name = "NAME")
private String name;
@Column(name = "CATEGORY", nullable = false)
private int category;
@Column(name = "JPAQLSTATEMENT", nullable = false)
private String jpaqlstatement;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "tblAdvFilter")
@Cascade ({@Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN}) })
private List<TblAdvFilterRow> tblAdvFilterRowCollection =
new ArrayList<TblAdvFilterRow>();
@ManyToOne(cascade=CascadeType.ALL)
@JoinTable(name = "TBLADVFILTERUSER", joinColumns =
{@JoinColumn(name = "FILTERID")}, inverseJoinColumns =
{@JoinColumn(name = "USERID")})
@Cascade ({@Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN}) })
private TblUser owner;
....
public void deleteAdvFilter(TblAdvFilter p_filter) throws SystemException {
try {
utx.begin();
TblAdvFilter filter = utx.get(TblAdvFilter.class, p_filter.getId());
utx.delete(filter);
utx.commit();
} catch (Exception ex) {
utx.rollback();
logger.severe(MessageUtil.getMessage("error.advfilter.errorDeletingFilter") + ex.getMessage());
}
|