We have a OneToMany relationship between two objects Emloyment and Business
and the Orphan deletion works fine if I am deleting all or some of elements
in Business during merge operation.
We get an Optimistic lock exception, if I am trying to delete the object
Emloyment with still some elements in the Business list.
Here are the domain files for Employment and Business classes
Employment.java
@Entity
@Table(name="EMPLOYMENT")
@NamedQueries({
@NamedQuery(name="getEmployment", query="SELECT x FROM Employment x")})
public class Employment implements Serializable{
@Transient
public final static String GET_INCOME = "getEmployment";
private static final long serialVersionUID = 211555224442567423L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "EMPLOYMENT_ID")
private long employmentId;
@OneToMany(mappedBy="employment", fetch=FetchType.EAGER,
cascade=CascadeType.ALL)
@ElementDependent
private List<Business> businessList;
public long getEmploymentId() {
return employmentId;
}
public void setEmploymentId(long employmentId) {
this.employmentId = employmentId;
}
public List<Business> getBusinessList() {
return businessList;
}
public void setBusinessList(List<BusinessCosts> businessList) {
this.businessList = businessList;
}
}
Business.java
@Entity
@Table(name="BUSINESS_COSTS")
@NamedQueries({
@NamedQuery(name="getAllBusinessCosts", query="SELECT x from BusinessCosts
x")})
public class Business implements Serializable{
private static final long serialVersionUID = 2111223224442567423L;
@Transient
public final static String GET_ALL_BUSINESS_COSTS =
"getAllBusinessCosts";
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="BUS_COST_ID", insertable=false)
private long businessCostsId;
@Column (name="BUS_COST_REASON_CD")
private String businessCostReasonCD;
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE,
CascadeType.PERSIST,CascadeType.REFRESH})
@JoinColumn(name="EMPLOYMENT_ID", referencedColumnName="EMPLOYMENT_ID")
private Employment employment;
public long getBusinessCostsId() {
return businessCostsId;
}
public void setBusinessCostsId(long businessCostsId) {
this.businessCostsId = businessCostsId;
}
public Employment getEmployment() {
return employment;
}
public void setEmployment(Employment employment) {
this.employment = employment;
}
}
Appreciate your help.
Thanks,
JP
--
View this message in context:
http://n2.nabble.com/Orphan-deletion-optimistic-lock-exception-tp3186163p3186163.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.