org.hibernate.exception.SQLGrammarException: 将 nvarchar 值 'ViewWebApp' 转换为数据类型 int 时转换失败
org.hibernate.exception.SQLGrammarException: Conversion failed when converting the nvarchar value 'ViewWebApp' to data type int
我正在尝试将 Hibernate 中的 NativeQuery 功能与 SQL 查询中的 JOIN 和子查询一起使用,但当我在 IN 条件下传递参数列表时它不起作用。
代码:
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);
错误:
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 创建查询方法:
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);
我正在尝试将 Hibernate 中的 NativeQuery 功能与 SQL 查询中的 JOIN 和子查询一起使用,但当我在 IN 条件下传递参数列表时它不起作用。
代码:
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);
错误:
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 创建查询方法:
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);