Hi all!
Im with a weird problem with a NOT IN clause.
I have this JPQL:
String jpql = "SELECT e FROM Entity e WHERE e NOT IN :colectionOfE";
TypedQuery<Entity> q = em.createQuery(jpql, Entity.class);
q.setParameter("colectionOfE", collection);
With this query, Eclipselink creates an query like that:
SELECT X,Y,Z from Entity e0 WHERE (e0.id not in (?))
But insted it binds the parameter to the ID collected on the itens of the passed collection, it maps to the toString() of the collection object.
Look at the real real code:
@Override
public Long getCountProdutosPorValorPropriedadeECategoria(
PropriedadeDado propriedadeDado, Categoria categoria,
Collection<Produto> produtosExclusao) {
String jpql = "SELECT COUNT(DISTINCT p) FROM Produto p WHERE p NOT IN :produtosExclusao AND p.categoria = :categoria AND p.ativo = :ativo AND :prop MEMBER OF p.propriedades";
TypedQuery<Long> q = getEntityManager().createQuery(jpql, Long.class);
//q.setParameter("produtosExclusao", ids);
q.setParameter("produtosExclusao", produtosExclusao);
q.setParameter("prop", propriedadeDado);
q.setParameter("categoria", categoria);
q.setParameter("ativo", true);
return q.getSingleResult();
}
And the erros:
JDBC message:
[2012-09-13 14:51:02.232] ERROR JavaFX Application Thread System.err Caused by: org.h2.jdbc.JdbcSQLException:
Hexadecimal string with odd number of characters: "1"; SQL statement:
[2012-09-13 14:51:02.232] ERROR JavaFX Application Thread System.err SELECT COUNT(DISTINCT(t0.PRODUTO_ID)) FRO
M GERAL.PRODUTO t0, GERAL.PRODUTO_DADO_PROPRIEDADE t2, GERAL.PROPRIEDADE_DADO t1 WHERE (((((t0.PRODUTO_ID NOT IN (?)) AND (t0.CATEGORIA_FK = ?)) AND (t0.ATIVO = ?)) AND
(? = t1.DADO_ID)) AND ((t2.PRODUTO_FK = t0.PRODUTO_ID) AND (t1.DADO_ID = t2.PROPRIEDADE_DADO_FK))) [90003-168]
Eclipselink debuglog:
)) FROM GERAL.PRODUTO t0, GERAL.PRODUTO_DADO_PROPRIEDADE t2, GERAL.PROPRIEDADE_DADO t1 WHERE (((((t0.PRODUTO_ID NOT IN (?)) AND (t0.CATEGORIA_FK = ?)) AND (t0.ATIVO = ?
)) AND (? = t1.DADO_ID)) AND ((t2.PRODUTO_FK = t0.PRODUTO_ID) AND (t1.DADO_ID = t2.PROPRIEDADE_DADO_FK)))
[2012-09-13 14:51:02.226] ERROR JavaFX Application Thread System.err bind => [br.com.mmds.totem.domain.Produt
o@20, 1, true, 4]
Look that it binds "br.com.mmds.totem.domain.Produto@20" insted "Produto" id.
The strange, is: If I change my query this:
SELECT COUNT(DISTINCT p) FROM Produto p WHERE p.id NOT IN :collectionOfIds
It works ..
Where is the problem?
Im using version: Eclipse Persistence Services - 2.4.0.v20120608-r11652
Thanks!!