Note that there are some explanatory texts on larger screens.

plurals
  1. POSpringData JPA hibernate collection for IN keyword
    primarykey
    data
    text
    <p>I am trying to fetch records using custome query in SpringData repository. I want to use IN keyword to fetch objects according to ids of a nested object. Following is my repo class.</p> <pre><code>public interface BusinessRepository extends JpaRepository&lt;Business, Long&gt; { @Query("SELECT t from Business t where t.address.addressid IN ? AND (t.businessType.text like ? or t.businessname like ?)") ArrayList&lt;Business&gt; findAllByAddressAddressidInAndBusinessTypeTextLikeOrBusinessnameLike(ArrayList&lt;Long&gt; ids, String businessType, String businessName); </code></pre> <p>My console shows following text.</p> <pre><code>Hibernate: select business0_.businessid as businessid0_, business0_.address_addressid as address9_0_, business0_.begdate as begdate0_, business0_.businessType_id as busines10_0_, business0_.businessname as business3_0_, business0_.contracttypeid as contract4_0_, business0_.multiuser as multiuser0_, business0_.statusid as statusid0_, business0_.urlreservos as urlreser7_0_, business0_.website as website0_, business0_1_.homePhone as homePhone2_, business0_1_.mobilePhone as mobilePh2_2_, business0_1_.primaryPhone as primaryP3_2_, business0_2_.businessdesc as business1_1_, business0_2_.pagetitle as pagetitle1_, business0_2_.tag as tag1_, business0_3_.userid as userid3_ from tbu1200 business0_ left outer join tbu1208 business0_1_ on business0_.businessid=business0_1_.id left outer join tbu1207 business0_2_ on business0_.businessid=business0_2_.id left outer join tbu1204 business0_3_ on business0_.businessid=business0_3_.businessid cross join vt1001 businessty1_ where business0_.businessType_id=businessty1_.id and (business0_.address_addressid in (?)) and (businessty1_.text like ? or business0_.businessname like ?) TRACE: org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [1, 2] </code></pre> <p>It seems correct to me. I am getting following exception.</p> <pre><code>java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Long at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36) at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:57) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92) </code></pre> <p>My question is that why it is expecting Long while I have used IN statement. It should expect a Collection. If this is something not supported then what should I do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload