hibernateTemplate hql batch update (delete, add, modify) is similar

To get the first Session, the following code, remember to close

public boolean updateCommodityName(BusinessImage businessImage) {
        try {
            logger.info(businessImage.toString());
            String hql="update BusinessImage b set b.commodityName='"+businessImage.getCommodityName()
                    + "' where b.commodityNumber='"+businessImage.getCommodityNumber()+"'";
            logger.info(hql);
            Session session = getHibernateTemplate().getSessionFactory().openSession();
            session.beginTransaction();
            Query query  = session.createQuery(hql);
            logger.info(query.executeUpdate());
            session.beginTransaction().commit();
            session.close();
            getHibernateTemplate().getSessionFactory().close();
            return true;
        } catch(Exception e) {
            return false;
        }
    }

To get the first Session, the following code, remember to close

public boolean updateCommodityName(BusinessImage businessImage) {
        try {
            logger.info(businessImage.toString());
            String hql="update BusinessImage b set b.commodityName='"+businessImage.getCommodityName()
                    + "' where b.commodityNumber='"+businessImage.getCommodityNumber()+"'";
            logger.info(hql);
            Session session = getHibernateTemplate().getSessionFactory().openSession();
            session.beginTransaction();
            Query query  = session.createQuery(hql);
            logger.info(query.executeUpdate());
            session.beginTransaction().commit();
            session.close();
            getHibernateTemplate().getSessionFactory().close();
            return true;
        } catch(Exception e) {
            return false;
        }
    }

Guess you like

Origin www.cnblogs.com/riyueqian/p/11487939.html