我正在尝试通过串联相同的列值来更新列。 即,我正在尝试编写类似“ 更新t_user设置名称= concat(name,“ 1-12-2016”),其中projectID = 212 ”的查询。为此,我尝试了所有这些情况。
-------------------------------------------------------
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaUpdate<AdminUser> update = builder.createCriteriaUpdate(AdminUser.class);
Root<AdminUser> root = update.from(AdminUser.class);
update.set(root.get("enabled"), false);
update.set("userName", builder.concat(unameTimestamp, root.get("userName")));
update.where(builder.equal(root.get("projectID"), userID));
session.createQuery(update).executeUpdate();
---------------------------------------------------------------
----------------------------------------------------------------
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaUpdate<AdminUser> update = builder.createCriteriaUpdate(AdminUser.class);
Root<AdminUser> root = update.from(AdminUser.class);
update.set(root.get("enabled"), false);
Expression<String> exp = builder.concat(unameTimestamp, root.get("userName"));
update.set("userName", exp);
update.where(builder.equal(root.get("projectID"), userID));
session.createQuery(update).executeUpdate();
tx.commit()
---------------------------------------------------------------
when ever I tried this I am getting
java.lang.ClassCastException: org.hibernate.query.criteria.internal.expression.ConcatExpression cannot be cast to java.lang.String
Or if I wrote like this
update.set(root.get("userName"), builder.concat(unameTimestamp, root.get("userName"))); I am getting compilation error as
The method set(Path<Expression<String>>, Expression<String>) is ambiguous for the type CriteriaUpdate<AdminUser>
Please can somebody help me.