我正在尝试使用 SpringData 存储库中的客户查询来获取记录。我想使用 IN 关键字根据嵌套对象的 id 获取对象。以下是我的回购课程。
public interface BusinessRepository extends JpaRepository<Business, Long> {
@Query("SELECT t from Business t where t.address.addressid IN ? AND (t.businessType.text like ? or t.businessname like ?)")
ArrayList<Business> findAllByAddressAddressidInAndBusinessTypeTextLikeOrBusinessnameLike(ArrayList<Long> ids, String businessType, String businessName);
我的控制台显示以下文本。
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]
这对我来说似乎是正确的。我收到以下异常。
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)
我的问题是,为什么在我使用 IN 语句时它会期待很长时间。它应该期待一个集合。如果这是不支持的东西,那我该怎么办?