【发布时间】:2016-07-11 22:46:52
【问题描述】:
我被休眠删除的集合类型卡住了,该集合类型在外部约束下给出异常。
这是我的休眠表
@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,SQL 状态:40001 超过锁定等待超时;尝试重启交易
请您建议我在哪里做错了。这里..
谢谢
【问题讨论】:
-
看看this SO post.可能会有帮助。
-
某个其他进程在您要删除的表或记录上锁定。找出它是什么并停止它。阅读here。