【发布时间】:2017-05-27 21:28:27
【问题描述】:
我想从一个表中选择所有字段,获取另一个表的记录,然后将记录插入到该表中。但是,我收到一条错误消息,指出这些值为空。这是相关的代码:
// Fetch
PersonDeactivatedRecord person = getContext().selectFrom(PERSON)
.where(PERSON.ID.eq(id))
.fetchOneInto(PersonDeactivatedRecord.class);
// Insert
person.setDeactivatedOn(new Timestamp(System.currentTimeMillis()));
getContext().insertInto(PERSON_DEACTIVATED)
.set(person)
.execute();
person_deactivated 表是person 表的副本加上一列 (deactivated_on)。我得到的错误是这样的:
org.jooq.exception.DataAccessException: SQL [insert into "xxx"."person_deactivated" ("deactivated_on") values (cast(? as timestamp))]; ERROR: null value in column "id" violates not-null constraint
Detail: Failing row contains (null, null, null, null, null, null, null, null, null, ...)
请注意,当我调试此代码时,我看到 person 对象已按预期完全填充。知道我在这里缺少什么吗?
【问题讨论】: