我的updatecriteria无法识别真正的列名

q5lcpyga  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(209)

下面是我的方法。从criteriabuilder生成的查询在日志中可见。无法获取真实的列名。

@Override
    @Transactional(value = TxType.REQUIRED)
    public void updateAttributes(BulkUpdateObject bulkUpdateObject , List<Long> idList) {
        List<Attribute> attributes = bulkUpdateObject.getAttributes();
        List<Event> events = bulkUpdateObject.getEvents();
        List<Long> eventList = idList;

            CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();

            CriteriaUpdate<Automation> updateCriteria = cb
                    .createCriteriaUpdate(Automation.class);
            Root<Automation> e = updateCriteria.from(Automation.class);

            for(Attribute attribute : attributes){

                updateCriteria.set(AttributeColumnNames.fromString(attribute.getField()).column(), getValue(attribute));
            }

            updateCriteria.where(e.get("idCaua").in(eventList)); 
            int count = entityManager.createQuery(updateCriteria).executeUpdate();

    }

以下是实体(部分)

@Entity
@Table(name = "AUTOMATION",schema = "platform", catalog = "platform")
public class Automation {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_CAUA", nullable = false)
    private Long idCaua;

    @Column(name = "EV_STATE")
    private String evState;

    @Column(name = "EV_STATE_ORIGIN")
    private String evStateOrigin;

}

下面是错误堆栈跟踪

20:17:34,364 INFO  [stdout] (default task-1) Hibernate: select currentala0_.ID_CAUA as col_0_0_ from platform.AUTOMATION currentala0_ where currentala0_.ID_CAUA in (? , ?)
20:17:34,805 INFO  [stdout] (default task-1) Hibernate: update platform.AUTOMATION set evState=?, evStateOrigin=? where idCaua in (15 , 16)
20:17:34,876 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) SQL Error: 1054, SQLState: 42S22
20:17:34,880 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) (conn=246) Unknown column 'idCaua' in 'where clause'
20:17:34,942 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to v1/operations/bulkUpdate: org.jboss.resteasy.spi.UnhandledException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:82)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:346)

Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)

Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)

Caused by: java.sql.SQLSyntaxErrorException: (conn=246) Unknown column 'idCaua' in 'where clause'
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:62)
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:153)

它应该转换为它的真实列名id\u caua,但它不能这样做。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题