db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Ezzio" <dez...@bea.com>
Subject RE: Behavior of projection queries (long)
Date Fri, 09 Jun 2006 03:33:05 GMT
Hi Craig,

Comments inline.


-----Original Message-----
From: Craig L Russell [mailto:Craig.Russell@Sun.COM]
Sent: Thu 6/8/2006 9:11 PM
To: JDO Expert Group; Apache JDO project
Subject: Behavior of projection queries (long)

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  

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).

cos.incorporated.setTime(new Date().getMillis());

cos.departments.add(new Department());


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


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  

dtos.incorporated.setTime(new Date().getMillis());

dtos.departments.add(new Department());


Maybe, but only if Address is a first class object.

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

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.

I'm sure you have a very good reason in mind.  Perhaps I missed it.

One the one side, I fail to see the virtues of this proposal.  On the other side, the whole
point of projections is to avoid instantiating first class objects (although the collections
produced may be collections of first class objects).  Likewise, projected values should never
be owned by first class objects.  

The proposal adds yet another corner case that will confuse, snare, and flabbergast application

In my opinion, the rule should always be: projected SCOs are never owned, projected FCOs are
always managed.  Modifying unowned SCOs never has an effect on the database.  Modifying FCOs
no matter how you get them always has an effect if the tx commits (except for the well know
corner case of modifying just the unowned side of a bidirectional relationship).  That's what
most developers would expect.


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!

Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

View raw message