关于CriteriaUpdate

时间:2017-03-24 14:07:47

标签: hibernate jpa eclipselink

下面的代码段,

@Entity
public class A {    
    @Id@GeneratedValue private Long id;
    private String name;
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
}

...

    tx.begin();
    em.persist(new A());
    tx.commit();

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaUpdate<A> update = cb.createCriteriaUpdate(A.class);
    Root<A> a = update.from(A.class);
    ParameterExpression<String> param = cb.parameter(String.class);

    tx.begin();
    em.createQuery(update.set(a.<String> get("name"), "julie")).executeUpdate();
    tx.commit();

    tx.begin();
    em.createQuery(update.set(a.<String> get("name"), param))
            .setParameter(param, "joe").executeUpdate();
    tx.commit();

Query#setParameter始终从IllegalArgumentException下方Hibernate-entitymanager(5.2.8.Final)退出,Eclipselink(2.6.4)也遇到类似问题。

java.lang.IllegalArgumentException: Could not resolve binding for given parameter reference 
[org.hibernate.query.criteria.internal.expression.ParameterExpressionImpl...]

@EDIT

  • 添加了无需调用#setParameter的测试,该测试已通过。

0 个答案:

没有答案