hi chandan,

this looks like a conflict in column names.
have you tried using an alias for project.name:

mainQuery.setAttributes(new String[] { "id" , "name" , "age" , "project.name as pname" });

hth
jakob

Chandan AHUJA schrieb:
Hello All ,
            I am facing one problem while using ReportQueryByCriteria  class .

Backdrop : I have 2 tables A) Employee(Id , name , age ,project__id) ;
B) project(id , name)


Here , "Project__id" field of the "employee" table is the foreign key referencing the "id" field of "project" table .
Following are the corresponding classes for the two tables



//Only attributes are shown here public class Employee {
private String id ;
private String name;
private Integer age ;
private Project project ;
private String projectId ; }


public class Project {
private String id ;
private String name ;
public Vector allEmployeesInProject ;


}

I have defined the relationship in repository_user.xml files for both the 
classes .

I want to make the following query ......

Select e.id , e.name , e.age , p.name from employee e, project p
where e.project__id= p.id and e.age > ( select avg(age) from employee ) I am using the following code for the same .
********************************************
subQuery = new ReportQueryByCriteria(Employee.class, subCriteria);
criteria.addGreaterThan("age" , subQuery) ;
mainQuery = new ReportQueryByCriteria(Employee.class, criteria);
mainQuery.setAttributes(new String[] { "id" , "name" , "age" , "project.name" });
subQuery.setAttributes(new String[] { "avg(age)" }); iterator = broker.getReportQueryIteratorByQuery(mainQuery);
System.err.println("Id " + "||" + "Name " + "Age " + "||" + " Project Name ") ;
while(iterator.hasNext())
{
Object result[] = (Object[])(iterator.next());
System.err.println( (String)result[0] + "||" + (String)result[1] + "||"+ ((BigDecimal)result[2]) + "||" + (String)result[3] ) ;
}
*********************************************************


I the log file spy.log I can see that the query generaed is exactly that I want .And it is producing the correct results when I run it on my data base But , I am facing a strange problem in the "column 4th"(project.name) when I try to print the result in stderr .
The 4th element ie the result[4] is showing the Name of the "employee" and not the name of the "project" .
When I copy the query from the log file and run it in its running the correct result ie the last column is the the project.name . Also , When I select "project.id" instead of "project.name" . I am getting the id of the projects , ie the correct results .


Please Help me .
Thanks in advance .

Chandan Ahuja




--------------------------------------------------------------------- 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]



Reply via email to