I am stuck over hibernate delete having collection type that is giving exception with foreign constraints.
Here is my Hibernate table
@Entity
@Table
public class FrontRequest implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long tutorfront_id;
@Column
private String tutorialType;
@Column
private String tutorialLevel;
@ElementCollection(fetch=FetchType.EAGER)
@Fetch(value = FetchMode.SELECT)
private Collection<String> tutorialSubjects= new HashSet<String>();
@Column
private String tutorialCity;
@Column
private String noOfStudent;
@Column
private String classWeek;
@Column
private String tutionFee;
@Column
private String tutionFeerate;
@Column
private String tutorSex;
@Column
private String tutorEducation;
@Column
private Date postingDate;
@Column
private String studentSchool;
}
and here is my service method to delete the object
public boolean removeFrontRequest(Long id) {
// TODO Auto-generated method stub
Session session= SessionFactoryImpl.returnService().getCurrentSession();
Transaction tx;
if(session.getTransaction() != null
&& session.getTransaction().isActive()){
tx=session.getTransaction();
}
else{
tx= session.beginTransaction();
}
try{
Query query=session.createQuery("from FrontRequest where tutorfront_id =:id");
query.setParameter("id", id);
FrontRequest frontRequest=(FrontRequest) query.list().get(0);
session.delete(frontRequest);
if(!tx.wasCommitted()) {
tx.commit();
}
}
catch(Exception e){
return false;
}
return true;
}
But it is giving exception with lock: SQL Error: 1205, SQLState: 40001 Lock wait timeout exceeded; try restarting transaction
Please can you suggest where I am doing wrong. Here..
Thanks