作为这个问题的继续
使用 hibernate 和 @JsonIgnore 获取 oneToMany 和 manyToOne
我有一个 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
我如何称呼新班级?我错过了什么?
发现问题我还需要将选择更改为
@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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句