我困在休眠刪除具有異常與外國約束的集合類型。休眠刪除字符串類型集合
這裏是我的休眠表
@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;
}
,這裏是我的服務方法刪除對象
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;
}
但它給人的異常與鎖: SQL錯誤:1205 SQLSTATE:40001 鎖超時超時;嘗試重新啓動交易
請你可以建議我在哪裏做錯了。這裏..
謝謝
看看[這個SO帖子。](http://stackoverflow.com/questions/5836623/getting-lock-wait-timeout-exceeded-try-restarting-transaction-even-though-im)它可能有幫助。 – rcyza
某些其他進程在您嘗試刪除的表或記錄上存在鎖定。找出它是什麼,並停止它。閱讀[這裏](http://www.coderanch.com/mobile/t/447114/ORM/databases/Error-Deleting-Persisted-Objects-Hibernate?foo=a)。 –