cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Paul Le Fèvre <>
Subject Re: Problem concerning Prefetching
Date Mon, 28 Jan 2008 15:29:35 GMT
On Monday 28 January 2008, Michael Gentry wrote:
> Hi Jean-Paul,

Hi Michael and Andrus,

> It looks like galaxy -> galaxy_component_properties is a to-one
> relationship, which would cause Cayenne to issue multiple selects like
> this since it tries to resolve each fault individually.

It's a one to many : each galaxy has 3 different types of properties.

Here is the code (simplified) implementing my method :

public final List<Galaxy> selectGalaxies(int timestep) 
    StringBuffer buf = new StringBuffer(" = '");
    buf.append("' and = ");

    Expression exp    = Expression.fromString(buf.toString());
    SelectQuery query = new SelectQuery(Galaxy.class, exp);
    query.addOrdering("number", true);


    return (List<Galaxy>) performQuery(query);

And here is how I use it :
galaxies = handler.selectGalaxies(ts);

// Loop on galaxies, get the disc component and the mass of baryons.
for (Galaxy g : galaxies) {

    GalaxyComponentProperties prop = g.getComponentProperties("disc");
    if (prop != null) {
        printer.println(g.getNumber() + ", " +

> Given your manual SQL statement:
> select galaxies.number, galaxy_component_properties.mass_of_baryons
>       from galaxy_component_properties
>       join galaxies on galaxy_component_properties.galaxy_id =
>       where some_clause
>       order by galaxies.number;
> It looks like you don't actually care about having actual Cayenne
> objects (it looks like you only care about having two of the
> attributes)?  If this is the case, you could use an SQLTemplate and
> raw data rows to only fetch in those two properties.  If this isn't
> the case, let us know and we'll give you other ideas.

In fact you asked the good question. I'm just at the beginning of the 
development and I don't really know how the application will be used and as a 
consequence it is hard to figure out what it the best strategy to implement 
the functionalities : I guess that some users are only interested in 
computing mean values, sums, min, max  in big chunks of data but others want 
to retrieve all the attributes of a small amount of specific objects. The 
challenge is to make both types of users happy. I'm wondering whether it is 
possible or not.
In my experience Cayenne has always been excellent at manipulating small 
numbers of complex objects but, on the other hand, difficult to use on huge 


Jean-Paul Le Fèvre  * Mail :

View raw message