Hibernate更新属性

    public boolean modifyDuration(long id, int dur) {
        final long contentId = id;
        final Integer duration= dur;
        final String hqlUpdate = "update Content set duration = :duration where CONTENTID_PK = :id";
        Integer result = (Integer)this.execute(new HibernateCallback() {
            
            public Object doInHibernate(Session session) throws HibernateException,
                    SQLException {
                return session.createQuery(hqlUpdate)
                    .setInteger( "duration", duration)
                    .setLong( "id", contentId )
                    .executeUpdate();
            }
        });
        boolean success = result == 1 ? true : false;
        return success;
    }

猜你喜欢

转载自even-ing.iteye.com/blog/2287712