hi roger,
i can confirm this problem.
this simple testcase shows the duplicates:
/**
* test OrderBy joined column
*/
public void testOrderByJoined2()
{
Criteria crit = new Criteria();
QueryByCriteria q = QueryFactory.newQuery(Project.class, crit);
q.addOrderByAscending("persons.lastname");
Collection results = broker.getCollectionByQuery(q);
assertNotNull(results);
// compare with count
int count = broker.getCount(q);
assertEquals(results.size(), count);
Set resultsSet = new HashSet(results);
assertEquals(resultsSet.size(), results.size());
}
jakob
Janssen, Roger schrieb:
Hi guys,
I have come across a bug. I included a method to be added to
org.apache.ojb.broker.QueryTest class in the OJB testsuite that
reproduces that bug, for version 1.0.4!
The test:
Create a project, create two persons, the two persons are a member of
the project, select all projects ordered by lastname of the persons, now
for every person within a project, the project appears in the resultset
instead of just appearing once. So if a project has 5 persons, that
project appears 5 times in the resultset.
This is a big problem for us, since instead of project- and
person-clasess, we have object- and attribute-classes, and now we are
not able to sort our objects by values of their attributes (every
attribute is a separate class with a name and value property).
The SQL query generated is okay, something like (i editted it somewhat
for readability):
SELECT DISTINCT A0.ORG_CONTEXT,A0.ENABLED,A0.ENTITY_CLASS,A1.VALUE as
ojb_col_49
FROM IBANX_LOG_EVENT A0 INNER JOIN IBANX_LOG_EVENT_ABSTRACTATTRIBUTE A1
ON A0.ID=A1.OID
WHERE (( A1.NAME = ?) AND (A1.VALUE LIKE ?)) ORDER BY 4
And off course, the join results in multiple rows for every available
A1.VALUE, but I expect OJB to instantiate the object only once in my
resultset!
The test method below iterates over the resultset and prints the project
titles to system.out, so in the test output you see duplicate projects
appearing in the resultset!
Add this method to org.apache.ojb.broker.QueryTest class(I added it just
below method testOrderByJoined):
/**
* test OrderBy joined column
*/
public void testOrderByJoinedIBanx()
{
System.out.println("testOrderByJoinedIBanx start");
String name = "testOrderByJoinedIBanx" +
System.currentTimeMillis();
Person p1 = new Person();
p1.setFirstname("tom");
p1.setLastname("jones");
Person p2 = new Person();
p2.setFirstname("tom");
p2.setLastname("hanks");
ArrayList list_1 = new ArrayList();
list_1.add(p1);
list_1.add(p2);
Project pj1 = new Project();
pj1.setTitle(name);
pj1.setPersons(list_1);
ArrayList list_projects = new ArrayList();
list_projects.add(pj1);
p1.setProjects(list_projects);
p2.setProjects(list_projects);
broker.beginTransaction();
broker.store(pj1);
broker.commitTransaction();
System.out.println("testOrderByJoinedIBanx stored data");
Criteria crit = new Criteria();
QueryByCriteria q = QueryFactory.newQuery(Project.class,
crit);
// compare with count
int count = broker.getCount(q);
q.addOrderByAscending("persons.lastname");
Collection results = broker.getCollectionByQuery(q);
assertNotNull(results);
// print items retrieved (resultset has duplicate items)
Iterator it = results.iterator();
while(it.hasNext())
{
Project rp = (Project) it.next();
System.out.println(" project = " +
rp.getTitle());
}
// compare with count
assertEquals(results.size(), count);
System.out.println("testOrderByJoinedIBanx end");
}
Roger Janssen
iBanx
*************************************************************************T
he information contained in this communication is confidential and is
intended solely for the use of the individual or entity to whom it is
addressed.You should not copy, disclose or distribute this communication
without the authority of iBanx bv. iBanx bv is neither liable for
the proper and complete transmission of the information has been maintainedn
or that the communication is free of viruses, interceptions or
interference.
If you are not the intended recipient of this communication please returnt
he communication to the sender and delete and destroy all copies.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]