I am trying to use the NativeQuery feature in Hibernate with JOIN and subqueries in SQL query, when I am passing the list of parameters with IN condition it's not working.
Code:
Query query1 = entityManager.createNativeQuery("select product0_.* from TEST.PRODUCT product0_ \n" +
"LEFT JOIN\n" +
"(select DISTINCT product1_.PRODUCT_ID from TEST.PRODUCT_GROUP_PERMISSION product1_ \n" +
"where product1_.GROUP_ID = 101 and product1_.PERMISSION_TYPE_ID in (:permissionTypes)\n" +
") \n" +
"AS ProductID ON product0_.PRODUCT_ID = ProductID.PRODUCT_ID where product0_.NAME=:productName and product0_.ACTIVE='1' \n" +
"and product0_.APPLICATION_ID = AppID.APPLICATION_ID order by upper(display_version)")
.setParameter("productName",productName)
.setParameter("permissionTypes",permissionTypes);
Error:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query] with root cause com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the nvarchar value 'ViewWebApp' to data type int.
Hibernate Create Query method:
Query cQuery = entityManager.createQuery("select product0_ from Product product0_ where product0_.name =:productN and product0_.active='1' and product0_.productId in (select product1_.application.applicationId from ApplicationGroupPermission product1_ where product1_.groups in (:myGroupIds) and product1_.permissionType.permissionTypeField in (:pList)) order by product0_.displayVersion asc ")
.setParameter("productN",productName)
.setParameter("pList",permissionTypes)
.setParameter("myGroupIds",myGroups);