我试着在eclipselink JPA中使用in子句,但是什么都没有用
final String parameterizedQuery = "Select * FROM sap.Preco WHERE cliente_id = ?clienteId and numero_material in ( ?numeroMaterial )";
listPreco = em.createNativeQuery(parameterizedQuery)
.setParameter("clienteId", clienteId).setParameter("numeroMaterial", produtoId)
.getResultList();produtoId id是一个带有逗号分隔值的字符串。
String produtoId = StringUtils.join(listMaterial, "','");或
String produtoId = StringUtils.join(listMaterial, ",");两者都不能工作,这是日志:
从sap.Preco选择* cliente_id =?和numero_material in (?)绑定=> 0000006775,000000000000100003,000000000000100003
已尝试使用列表作为参数,但不起作用。
内部异常: org.postgresql.util.PSQLException:无法推断要用于java.util.ArrayList实例的SQL类型。使用具有特定值类型的setObject()指定要使用的类型。
发布于 2018-02-26 14:54:02
不能使用逗号分隔的字符串,而且JDBC不支持带参数的IN。
阅读更多关于您所拥有的选项的信息:https://javachannel.org/posts/using-sqls-in-in-jdbc/
发布于 2018-02-26 16:49:54
尝试移除命名参数周围的括号:
final String parameterizedQuery = "Select * FROM sap.Preco WHERE cliente_id = ?clienteId and numero_material in ?numeroMaterial ";并将字符串列表作为参数传递:
em.setParameter("numeroMaterial", listMaterial);https://stackoverflow.com/questions/48990932
复制相似问题