简体   繁体   中英

hibernate link 2 java files to the same DB table

as a continue to this question

fetch oneToMany and manyToOne using hibernate and @JsonIgnore

I have an issue with the JsonIgnore I was thinking to build one object that has the JsonIgnore annotation and one object that does not have it. when I am trying to use the new object it is still using the old object - what am i missing ?

this is the new code (CategoryIgnoreJson is the new class that I created )

    @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;

}

I also created new repository

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( );

}

I can see in the log file that the old Category is still called I also changed the table name in old category from categories to categories1 (just to validate that this code is called ) and got the expected error

edi_ms.categories1" does not exist

how do I call the new class ? what am I missing ?

Found the issue I also needed to change the select to

    @Query("from CategoryIgnoreJson ..."

also change the value of the mapped by to refer to the name of the object that is is mapped to in the parrent (in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM