cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: SQLTemplate returning NULL results
Date Tue, 28 May 2013 07:24:06 GMT
I think I've seen it before. This could the column naming in the result set not exactly matching
DbEntity. Try this maybe: 

 query.setColumnNamesCapitalization(CapsStrategy.LOWER);

And yes, we need to improve this in Cayenne - instead of NULLs we prolly need to throw an
Exception or something.

Andrus


On May 28, 2013, at 9:52 AM, giulio.cesare@gmail.com wrote:

> Hello everybody,
> 
> I am getting lost in trying to use an SQLTemplate query.
> 
> I have tried to reduce the problem to the core, and this is the point where
> I am stuck.
> 
> The following two lines of code do what I was expecting them to do:
>    Query query = new SelectQuery(SaleSummary.class);
>   List<SaleSummary> saleSummariesToProcess =
> objectContext.performQuery(query);
> 
> Looking into the logs, this is the SQL statement generated automatically by
> Cayenne:
>> SELECT t0.amount, t0.unique_id, t0.period, t0.registrationDate,
>> t0.id_contract, t0.id_currency, t0.id_customer, t0.id_frontendSystem,
>> t0.id_saleSummary, t0.id_store FROM wolf.SaleSummary t0
> 
> So far, so good. But as soon as I replace the SelectQuery with a
> SQLTemplate, I can no longer get any result. Actually, I get the expected
> results, but instead of being instances of SaleSummary, the list contains
> all nulls.
> 
> I need to run a fairly complex query that I would like to store into the
> model, but also the most trivial tests are failing.
> 
> I have tried all the following options, all with the same bad result:
> - query = new SQLTemplate(SaleSummary.class, "select * from salesummary");
> - query = new SQLTemplate(SaleSummary.class, "SELECT * FROM SALESUMMARY");
> - query = new SQLTemplate(SaleSummary.class, "SELECT t0.amount,
> t0.unique_id, t0.period, t0.registrationDate, t0.id_contract,
> t0.id_currency, t0.id_customer, t0.id_frontendSystem, t0.id_saleSummary,
> t0.id_store FROM wolf.SaleSummary t0");
> 
> This latest option includes the same exact SQL query logged by the initial
> working code (that was using the SelectQuery class instead of SQLTemplate).
> 
> Am I doing something blatantly wrong, or is there something weird going on
> here?
> 
> BTW, I am using Cayenne 3.1B2. I was tempted to go back to 3.0.2, but being
> the model files not compatible, I was trying to understand why it is not
> working on 3.1B2 first.
> 
> Any hints?
> 
> Best regards,
> 
> Giulio Cesare


Mime
View raw message