Java 更新查询,工作正常,但不是i dao类

Java 更新查询,工作正常,但不是i dao类,java,mysql,hibernate,dao,Java,Mysql,Hibernate,Dao,同样的查询在mysql workbrench中运行良好,但当我在程序中运行它时,并没有结果,甚至并没有错误。我真的不知道怎么解决这个问题 我正在使用hibernate 5.0.0和mysql连接器5.0.5 道看起来像这样: Session session = null; Transaction tx = null; try { session = HibernateAnnotationUtil.getSessionFactory().openSession()

同样的查询在mysql workbrench中运行良好,但当我在程序中运行它时,并没有结果,甚至并没有错误。我真的不知道怎么解决这个问题

我正在使用hibernate 5.0.0和mysql连接器5.0.5

道看起来像这样:

Session session = null;
    Transaction tx = null;

    try {
        session = HibernateAnnotationUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        String hql = "UPDATE cms_asset SET `value` = CASE application_structure_id "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
                + "ELSE `value` END WHERE application_structure_id > 0;";
        Query query = session.createSQLQuery(hql);
        query.setParameter(0, "asd");
        ...
        query.setParameter(26, "asd2");
        Integer result = query.executeUpdate();
        tx.commit();
        if(result > 0){
            return true;
        }else {
            return false;
        }   

    } catch (Exception e) {
        try {
            tx.rollback();
        } catch (RuntimeException rbe) {
            rbe.printStackTrace();
        }
        e.printStackTrace();
        return null;
    } finally {
        if (session != null) {
            session.close();
        }
    }

据我所知,您必须使用该接口来处理本机SQL更新。例如

    SQLQuery query = session.createSQLQuery(hql);
    query.setParameter(0, "asd");
    ...
    query.setParameter(26, "asd2");
    Integer result = query.executeUpdate();

否则,您可能需要使用。但HQL将是最好的选择。

据我所知,您必须使用该接口来处理本机SQL更新。例如

    SQLQuery query = session.createSQLQuery(hql);
    query.setParameter(0, "asd");
    ...
    query.setParameter(26, "asd2");
    Integer result = query.executeUpdate();

否则,您可能需要使用。但是HQL将是最好的选择。

问题的解决方案是将引擎表从InnoDB更改为MyISAM,然后更新工作正常。

问题的解决方案是将引擎表从InnoDB更改为MyISAM,然后更新工作正常。

完成了吗?它跑了吗?它会引发异常吗?(假设您遗漏的代码不会影响操作)。你们调试过了吗?它工作正常,但数据库中并没有变化。我没有任何线索。此查询的结果是表中的行数。没有例外,什么都不完整吗?它跑了吗?它会引发异常吗?(假设您遗漏的代码不会影响操作)。你们调试过了吗?它工作正常,但数据库中并没有变化。我没有任何线索。此查询的结果是表中的行数。没有例外,什么都没有