java - Return a boolean from a JpaRepository method -


i have native query in interface extends jparepository. method should ideally return boolean value, can't figure out how select gets automatically translated boolean.

this works, although have call boolean.valueof(haskids(id)):

// yuck. wanted boolean @query(nativequery = true, value = "select 'true' dual exists("           + "select * child_table parent_id = ?)") string haskids(long parentid); 

how can change more natural return type?

boolean haskids(long parentid);  // throws classcastexception 

update:

the stacktrace not helpful imho because it's usual nightmare of hibernate proxies , aspectj closures, here's relevant portion anyway.

caused by: java.lang.classcastexception: java.lang.string cannot cast java.lang.boolean     @ com.sun.proxy.$proxy1025.haskids(unknown source)     @ com.bela.foo.bar.service.thingyserviceimpl.recordhaskids_aroundbody4(thingyserviceimpl.java:85)     @ com.bela.foo.bar.service.thingyserviceimpl$ajcclosure5.run(thingyserviceimpl.java:1) ... 

i think want check row exist or not parent id,and return true , false on basis of that, go case.

changes made in query

    "select case when (count(*) >0) true else false end dual exists("       + "select * child_table parent_id = ?) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -