为了账号安全,请及时绑定邮箱和手机立即绑定

休眠将 2 个 java 文件链接到同一个数据库表

休眠将 2 个 java 文件链接到同一个数据库表

宝慕林4294392 2021-12-30 20:07:14
我有一个 JsonIgnore 问题我正在考虑构建一个具有 JsonIgnore 注释的对象和一个没有它的对象。当我尝试使用新对象时,它仍在使用旧对象 - 我错过了什么?这是新代码(CategoryIgnoreJson 是我创建的新类)    @GET@Produces(MediaType.APPLICATION_JSON)@Path("getCategoriesQandA")public List<CategoryIgnoreJson> getCategoriesQandA() {    ediUtils = new EDIUtils(SYSTEM_NAME, USER_NAME);    Init(ediUtils);    ediUtils.writeToLog("get Categories , questions and answers ");    List<CategoryIgnoreJson> categoriesArray;    categoriesArray = categoryIgnoreJsonRepository.getEffective();    return categoriesArray;}我还创建了新的存储库public interface CategoryIgnoreJsonRepository extends JpaRepository<CategoryIgnoreJson, Long>{@Transactional @Modifying@Query("update  Category set expiration_date = current_date() where category_id = ?1 ")void expireCategory(Long id );  @Query("from Category where function ('coalesce' ,effectiveDate ,current_date() ) <= current_date() "        + "and function('coalesce' ,expirationDate , to_date('50001231','yyyymmdd')) > current_date() ")List<CategoryIgnoreJson> getEffective( );}我可以在日志文件中看到旧的类别仍然被称为我还将旧类别中的表名从类别更改为类别 1(只是为了验证此代码被调用)并得到预期的错误edi_ms.categories1" does not exist我如何称呼新班级?我错过了什么?
查看完整描述

1 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

发现问题我还需要将选择更改为


    @Query("from CategoryIgnoreJson ..."

还要更改映射的值以引用在父级中映射到的对象的名称(在 CatagoryIgnoreJson.java 中)


@OneToMany(fetch = FetchType.EAGER, mappedBy = "categoryIgnoreJson")

@Fetch(FetchMode.SUBSELECT)

@NotFound(action = NotFoundAction.IGNORE)

public List<QuestionIgnoreJson> getQuestions() {

    return this.questions;enter code here


查看完整回答
反对 回复 2021-12-30
  • 1 回答
  • 0 关注
  • 137 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号