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

我有一个 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

我如何称呼新班级?我错过了什么?


宝慕林4294392
浏览 138回答 1
1回答

慕哥9229398

发现问题我还需要将选择更改为&nbsp; &nbsp; @Query("from CategoryIgnoreJson ..."还要更改映射的值以引用在父级中映射到的对象的名称(在 CatagoryIgnoreJson.java 中)@OneToMany(fetch = FetchType.EAGER, mappedBy = "categoryIgnoreJson")@Fetch(FetchMode.SUBSELECT)@NotFound(action = NotFoundAction.IGNORE)public List<QuestionIgnoreJson> getQuestions() {&nbsp; &nbsp; return this.questions;enter code here
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java