Javadogs,

For the JDO maintenance release, we have to decide what the behavior is for projection queries of various kinds of fields. [There are no TCK tests for this behavior.] Consider this class:

class Company {
int id;
String symbol;
Date incorporated;
BigDecimal revenues;
Set<Department> departments;
Locale hqLocale;
Integer empCount;
Address hqAddress;
}

and these JDOQL queries:

Collection<DTOCompany> dtos = execute this query: "SELECT new DTOCompany(symbol, incorporated, revenues, departments, hqLocale, empCount, hqAddress) FROM Company ORDER BY id"

Collection<Company> cos = execute this query: "SELECT FROM Company ORDER BY id"

1. Now, iterate the collections of dtos and cos. For each corresponding result dto and co in the collection of results:

For each of symbol, incorporated, revenues, departments, hqLocale, empCount, and hqAddress:

Does dto.symbol == co.symbol?
Does dto.symbol.equals(co.symbol)?

2. Now, suppose I change the mutable second class fields of the instances I get from cos (the persistent instances).

tx.begin();
cos.incorporated.setTime(new Date().getMillis());
tx.commit();

tx.begin();
cos.departments.add(new Department());
tx.commit();

tx.begin();
cos.hqAddress.setState("CA");
tx.commit();

Have I modified the company instance in the database in any of these cases?

3.Now, suppose I change the mutable second class fields of the instances I get from dtos (the holders for the field values of the instances).
 
tx.begin();
dtos.incorporated.setTime(new Date().getMillis());
tx.commit();

tx.begin();
dtos.departments.add(new Department());
tx.commit();

tx.begin();
dtos.hqAddress.setState("CA");
tx.commit();

Have I modified the company instance in the database in any of the cases?

Here's a proposal to clarify the specification.

If mutable second class fields are selected by a projection query, the instances returned by the query are the instances of the owning first class instance. Changes made to the results are reflected in the database at transaction commit. There is no requirement that immutable fields returned by a projection query are identical to corresponding fields in cached instances.

The implication is that a projection query that selects mutable second class fields has the effect of instantiating the owning first class instance and associating the mutable second class fields in the query result with the owning first class instance. So selecting first name, last name, age, and ssn returns only values not associated with persistent instances. But selecting incorporated, departments, or hqAddress will instantiate the first class instances and its default fetch group.

 Craig

Craig Russell

Architect, Sun Java Enterprise System http://java.sun.com/products/jdo

408 276-5638 mailto:Craig.Russell@sun.com

P.S. A good JDO? O, Gasp!