开发者社区> 问答> 正文

JFinal Ctrl中 开启事物 有外键保存报错问题?报错

在controller里面 开启事物 Tx.class
然后先保存一个表a,然后再保存表b,表b中有先前保持表a的id外键
报错:
Caused by: com.jfinal.plugin.activerecord.ActiveRecordException: com.jfinal.plugin.activerecord.ActiveRecordException: The attribute name is not exists: id


展开
收起
爱吃鱼的程序员 2020-06-20 16:50:25 408 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    引用来自“小鲅鱼”的评论

    @RequiresPermissions("category:i18n")@Before({CategoryI18nEditValidator.class,Tx.class})publicvoidi18n(){...ACategoryModelacm=newACategoryModel();acm.set(ACategoryModel.NAME,name);acm.set(ACategoryModel.PARENT_ID,parentId);acm.set(ACategoryModel.DESCRIPTION,StringEscapeUtils.escapeHtml4(description));acm.set(ACategoryModel.TYPE,ACategoryModel.TYPE_I18N);acm.save();ACategoryLanguageModelcategoryLanguage=newACategoryLanguageModel();categoryLanguage.set(ACategoryLanguageModel.CATEGORY_ID,acm.getInt(ACategoryModel.ID));categoryLanguage.set(ACategoryLanguageModel.PARENT_ID,id);categoryLanguage.set(ACategoryLanguageModel.LANGUAGE_ID,languageId);categoryLanguage.save();...}



    回复 @JFinal:是的正常了~~thx回复 @小鲅鱼:现在完全正常了吧?回复 @JFinal:刚才看了一下数据库,发现是id出问题,不知谁把id改成int了,郁闷回复 @小鲅鱼:id使用程序来生成可以搞定回复 @JFinal:去掉事务是可以的addMapping("table_name","primary_key_name",YourTable.class) 贴代码出来主要是事务提交问题在Ctrl下面使用Tx.class可不可手动提交事物 @RequiresPermissions("category:i18n")@Before({CategoryI18nEditValidator.class,Tx.class})publicvoidi18n(){...ACategoryModelacm=newACategoryModel();acm.set(ACategoryModel.NAME,name);acm.set(ACategoryModel.PARENT_ID,parentId);acm.set(ACategoryModel.DESCRIPTION,StringEscapeUtils.escapeHtml4(description));acm.set(ACategoryModel.TYPE,ACategoryModel.TYPE_I18N);acm.save();ACategoryLanguageModelcategoryLanguage=newACategoryLanguageModel();categoryLanguage.set(ACategoryLanguageModel.CATEGORY_ID,acm.getInt(ACategoryModel.ID));categoryLanguage.set(ACategoryLanguageModel.PARENT_ID,id);categoryLanguage.set(ACategoryLanguageModel.LANGUAGE_ID,languageId);categoryLanguage.save();...}



    引用来自“小鲅鱼”的评论

    @RequiresPermissions("category:i18n")@Before({CategoryI18nEditValidator.class,Tx.class})publicvoidi18n(){...ACategoryModelacm=newACategoryModel();acm.set(ACategoryModel.NAME,name);acm.set(ACategoryModel.PARENT_ID,parentId);acm.set(ACategoryModel.DESCRIPTION,StringEscapeUtils.escapeHtml4(description));acm.set(ACategoryModel.TYPE,ACategoryModel.TYPE_I18N);acm.save();ACategoryLanguageModelcategoryLanguage=newACategoryLanguageModel();categoryLanguage.set(ACategoryLanguageModel.CATEGORY_ID,acm.getInt(ACategoryModel.ID));categoryLanguage.set(ACategoryLanguageModel.PARENT_ID,id);categoryLanguage.set(ACategoryLanguageModel.LANGUAGE_ID,languageId);categoryLanguage.save();...}



    2020-06-20 16:50:43
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载