> Is there a way to set up something in cayenne to match the functionality
> of using a view in Oracle?
>
> I've looked at the SqlSelectQuery, but it's not clear how to use it. The
> constructors all seem to reference a single entity, but I want to do a
> join using 4 tables.
>
> Is there a piece of example code for SqlSelectQuery?
Unfortunately this is not documented well now. But you are right,
SqlSelectQuery is the answer. You can run an arbitrary SQL SELECT
statement. In the simpliest case, root entity is required for routing
purposes only, and may not even be related to the tables participating in
the query (your application can have more than one DataNode, so we need to
know which node to use for the query). Note that returned result will
always be a "data row", not an object.
Here is a simple example:
String sql = "select t0.name as me, t1.name as boss "
+ "from employee t0, employee t1 "
+ "where t0.manager_id = t1.employee_id";
SqlSelectQuery query = new SqlSelectQuery(Employee.class);
query.setSqlString(sql);
Iterator employees = ctxt.performQuery(query).iterator();
while(employees.hasNext()) {
Map emp = (Map)employees.next();
System.out.prinltn("Name: " + emp.get("me"));
System.out.prinltn("Boss's Name: " + emp.get("boss"));
}
Andrus
This archive was generated by hypermail 2.0.0 : Fri Mar 21 2003 - 12:36:41 EST