Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem filtering with NOT IN clause(Weird problem with values collected from the collection)
Problem filtering with NOT IN clause [message #912528] Thu, 13 September 2012 17:57 Go to next message
Eduardo Frazão is currently offline Eduardo FrazãoFriend
Messages: 123
Registered: January 2012
Senior Member
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 Smile..

Where is the problem?

Im using version: Eclipse Persistence Services - 2.4.0.v20120608-r11652

Thanks!!
Re: Problem filtering with NOT IN clause [message #916056 is a reply to message #912528] Tue, 18 September 2012 13:15 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Seems like a bug. Check the latest patch/build of EclipseLink to see if it has been fixed (sounds familiar).
Otherwise log the bug.



James : Wiki : Book : Blog : Twitter
Previous Topic:EclipseLink-48
Next Topic:Metadata Class not generated by CanonicalModelProcessor
Goto Forum:
  


Current Time: Wed Apr 24 22:28:33 GMT 2024

Powered by FUDForum. Page generated in 0.03030 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top