CriteriaUpdate错误

时间:2017-04-27 07:30:40

标签: jpa criteria

我更新表格注册中的数据,该表格将OneToOne与表格用户

相关联
        CriteriaBuilder qb = em.getCriteriaBuilder();
        CriteriaUpdate<User> query = qb.createCriteriaUpdate(User.class);
        Root<User> root = query.from(User.class);

        query.set(root.get(User_.registration).get(Registration_.attempts), 0);
        query.where(root.get(User_.id).in(userIDlist));
        em.createQuery(query).executeUpdate();

所以我有错误

16:40:12,207 INFO  [stdout] (default task-24) 2017-04-26 16:40:12 ERROR DEBUG_LOGGER:463 - ClientFacadeBean#resetSmsCount - {}
16:40:12,207 INFO  [stdout] (default task-24) javax.persistence.PersistenceException: Exception [EclipseLink-6135] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.QueryException
16:40:12,207 INFO  [stdout] (default task-24) Exception Description: Attribute name or expression passed as a first parameter to addUpdate method defines a field from a table that's not mapped to query descriptor. 
16:40:12,207 INFO  [stdout] (default task-24) Attribute name or Expression: [
16:40:12,207 INFO  [stdout] (default task-24) Query Key attempts
16:40:12,207 INFO  [stdout] (default task-24)    Query Key registration
16:40:12,207 INFO  [stdout] (default task-24)       Base QUERY OBJECT]
16:40:12,207 INFO  [stdout] (default task-24) Wrong field: [REGISTRATION.ATTEMPTS]
16:40:12,207 INFO  [stdout] (default task-24) Descriptor: [RelationalDescriptor(by.softclub.model.entity.User --> [DatabaseTable(USER)])]
16:40:12,207 INFO  [stdout] (default task-24) Query: UpdateAllQuery(referenceClass=User )
16:40:12,207 INFO  [stdout] (default task-24)   at org.eclipse.persistence.internal.jpa.QueryImpl.executeUpdate(QueryImpl.java:308)

我做错了什么?

添加一些信息...

用户实体

...
    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    public Registration getRegistration() {
        return registration;
    }
...

注册实体

...
    @Id
    @GeneratedValue(generator = "registration")
    @TableGenerator(name = "registration", table = "SEQUENCES_TABLE",
            pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
            pkColumnValue = "registrationId",
            initialValue = 1, allocationSize = 1)
    private long id;
    @Column(name = "MESSAGE_CODE", nullable = false)
    private String messageCode;
    @Column(name = "CODE_EXPIRY", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date codeExpiry;
    @Column(nullable = false)
    private int attempts;
...

0 个答案:

没有答案