主题:Mapper 查询出来的对象主键为null

facer 2019年05月09日 128
TemplateMessage message = templateMessageMapper.createLambdaQuery().andEq("msgId", msgID).select().get(0); 
message.setPushUserResult(status);
templateMessageMapper.updateById(message);

上面的message查询出来debug显示的id为null,实际数据库id是有值的。

导致我下面那句更新语句出错,org.beetl.sql.core.BeetlSQLException: 主键未发现,com.cross.voicetodo.model.TemplateMessage,检查数据库表定义或者NameConversion

闲大赋 2019年05月09日

没有定义主健吧,你确保你TemplateMessage 定义了数据库匹配的主健,并且用@AssingId,或者@AutoId等注解表明这个是一个主健

facer 2019年05月09日

定义了AutoID,只不过是父类,这样会有影响吗?

public class TemplateMessage extends BaseModel {

    private String toUser;    private String templateId;    private String appId;    private String msgId;    private String title;    private String planContent;    private String userName;    private String planTime;    private String remark;    private String pushWeixinResult;    private String pushUserResult;    public interface Mapper extends BaseMapper<TemplateMessage> {
    }

    public String getToUser() {
        return toUser;    }

    public void setToUser(String toUser) {
        this.toUser = toUser;    }

    public String getTemplateId() {
        return templateId;    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;    }

    public String getAppId() {
        return appId;    }

    public void setAppId(String appId) {
        this.appId = appId;    }

    public String getMsgId() {
        return msgId;    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;    }

    public String getTitle() {
        return title;    }

    public void setTitle(String title) {
        this.title = title;    }

    public String getPlanContent() {
        return planContent;    }

    public void setPlanContent(String planContent) {
        this.planContent = planContent;    }

    public String getUserName() {
        return userName;    }

    public void setUserName(String userName) {
        this.userName = userName;    }

    public String getPlanTime() {
        return planTime;    }

    public void setPlanTime(String planTime) {
        this.planTime = planTime;    }

    public String getRemark() {
        return remark;    }

    public void setRemark(String remark) {
        this.remark = remark;    }

    public String getPushWeixinResult() {
        return pushWeixinResult;    }

    public void setPushWeixinResult(String pushWeixinResult) {
        this.pushWeixinResult = pushWeixinResult;    }

    public String getPushUserResult() {
        return pushUserResult;    }

    public void setPushUserResult(String pushUserResult) {
        this.pushUserResult = pushUserResult;    }
}
public class BaseModel implements Serializable {

    @AutoID    protected Long id;    protected Date createTime;    protected Date modifyTime;    public BaseModel() {
        this.createTime = new Date();        this.modifyTime = new Date();    }

    public Long getId() {
        return id;    }

    public Date getCreateTime() {
        return createTime;    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;    }

    public Date getModifyTime() {
        return modifyTime;    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;    }
}
闲大赋 2019年05月09日

有影响,不能定义在父类