Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » IN query with composite primary key bug.
IN query with composite primary key bug. [message #1034742] Fri, 05 April 2013 20:58
Michael Nielson is currently offline Michael Nielson
Messages: 15
Registered: April 2011
Junior Member
I'm trying to figure out this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=401569

The bug is an issue with table alias assignments for IN queries on composite keys.

The SQL I want to generate is this:

SELECT * FROM BUG t1 LEFT OUTER JOIN DEGREE t0 ON (t0.DEGREE_ID = t1.DEGREE_DEGREE_ID) WHERE ((t1.ID2, t1.ID1) IN ((?,?)))


Instead I get this:

SELECT * FROM BUG t1 LEFT OUTER JOIN DEGREE t0 ON (t0.DEGREE_ID = t1.DEGREE_DEGREE_ID) WHERE (([i][color=red]BUG.ID2, BUG.ID1[/color][/i]) IN ((?,?)))


To generate this with an expression builder I'm doing this (the bug has a complete example/test case), this is the same query generated by BatchFetchType.IN

ClassDescriptor descriptor = entityManager.getServerSession().getDescriptor(Bug.class);
List<Expression> fields = new ArrayList<Expression>(descriptor.getPrimaryKeyFields().size());
for(DatabaseField field : descriptor.getPrimaryKeyFields()) {
	fields.add(exp.getField(field));
}

// example pulled from org.eclipse.persistence.internal.databaseaccess.DatabasePlatform#buildBatchCriteriaForComplexId
exp = exp.value(fields).in(new List[]{Arrays.asList("one", "two")});


When I debug down into printSQL in SQLSelectStatement the baseExpression (ExpressionBuilder) for my two IN fields is different from the baseExpression on other expressions in the query. The correct base's all have tableAliases defined, the base attached to these IN fields does not have any tableAliases (tableAliases==null).

Should the base be shared between expressions or should tableAliases have been set earlier in the prepare phase?

My model for the expression tree is something like this:


  • 1 Expression base for the root
  • 1 Expression base for each table in the query
  • 1 Expression base for each field on each table


Is this correct? I'm having a hard time visualizing what the expression tree needs to look like.









Previous Topic:Eclipselink Query show's different data than resultset
Next Topic:Problem with Class DB2Platform function printSQLSelectStatement
Goto Forum:
  


Current Time: Wed Sep 03 04:53:13 GMT 2014

Powered by FUDForum. Page generated in 0.10081 seconds