1

I am trying to run a subquery in hibernate like this:-

DetachedCriteria cartProductIds = DetachedCriteria.forClass(UserCart.class,"usercart")
                                        .add(Restrictions.eq("is_deleted", false))
                                        .add(Property.forName("usercart.user_id").eq(Property.forName("search.userId")))
                                        .add(Property.forName("usercart.product_id").eq(Property.forName("search.productId")))
                                        .setProjection(Projections.property("product_id"));

List<SearchHistory> history=session.createCriteria(SearchHistory.class,"search")
                                .add(Restrictions.between("creationTime", startTime, Timings.getCurrentTime()))
                                .add(Restrictions.eq("notification_send", false))
                                .add(Subqueries.notIn("productId", cartProductIds))
                                .list();

But there is a error on notIn subquery line which shows as :-

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long.

Need help to solve this issue.Thanks!

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
Ayush Srivastava
  • 444
  • 1
  • 4
  • 13

0 Answers0