hibernate删除字符串类型集合

时间:2016-03-24 10:59:33

标签: java mysql hibernate hql

我遇到了hibernate delete,它的集合类型给出了异常的外部约束。

这是我的Hibernate表

@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 超出锁定等待超时;尝试重新启动交易

请问你能说明我做错了什么。这里..

由于

1 个答案:

答案 0 :(得分:0)

通过将= =替换为=来更正if条件。提交后也结束交易。