Home object references an unsaved transient instance - save the transient instance before flushing( while Fetch Query JPA)
Reply: 0

object references an unsaved transient instance - save the transient instance before flushing( while Fetch Query JPA)

user2054
1#
user2054 Published in April 25, 2018, 6:14 pm

The Question has been already asked here , but my context is different. I am querying (table name-reports_tbl ,Entity name -Report) to take out reports based on join_column menu_id in above table which joins to (Table name-menu_tbl,Entity name-Menu),using query

List<Report> reports= entityManager.createQuery(
                "SELECT r FROM Report r WHERE r.menu IN :reports_menu_id",Report.class)
                .setParameter("reports_menu_id",menu)
                .getResultList();

In Report Entity, member variable menu is declared like :

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="menu_pk")
protected Menu menu;

In Menu Entity reports is declared like :

@OneToMany(
            fetch=FetchType.LAZY,
            mappedBy="menu",
            cascade=CascadeType.ALL
        )
protected List<Report> reports = new ArrayList<Report>(); 

But i am getting the ABOVE EXCEPTION if i try to pass Menu object to setParameter reports_menu_id.

Menu menu = new Menu();
menu.setMenuId(Long.parseLong("12"));

if i pass 12 to the query generated it returns rows.

select report0_.id as id1_3_,... report0_.table_of_contents as table_o24_3_ 
from reports_tbl report0_ 
where report0_.menu_pk in (?) <-- generated query in hibernate

select report0_.id as id1_3_,...report0_.table_of_contents AS table_o24_3_
FROM
reports_tbl report0_
WHERE
report0_.menu_pk IN (12);<-- executed manually by passing value=12 

Am i missing something. Directly passing string value 12 :

List<Report> reports= entityManager.createQuery(
                "SELECT r FROM Report r WHERE r.menu IN 
:reports_menu_id",Report.class)
                .setParameter("reports_menu_id","12")
                .getResultList();

says Parameter value [12] did not match expected type [com.xyz.entity.Menu (n/a)] .Waiting for any Help.Thanks

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310138 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO