cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Evgeny Ryabitskiy <>
Subject Re: SQLTemplate with SQL MAX function
Date Fri, 02 Oct 2009 14:17:10 GMT
If you still interested.. I found a solution of how to perform simple
SQLTemplate query without mapping.
In you example it will be like:

DataMap someDataMap = ..... // get it from somewhere... e.g. from DataContext

SQLTemplate template = new SQLTemplate(someDataMap, "SELECT
max(ordering) as MAX_ORDERING FROM user_bookmark WHERE userid=$uid");
template.setParameters(Collections.singletonMap("uid", user.getId()));
List<DataRow> res = context.performQuery(template);

Integer maxOrdering = null;
if (res != null) {
   DataRow row =res.get(0);
   if (row != null) {
       maxOrdering = (Integer) row.get("MAX_ORDERING");
if (maxOrdering == null) {
   maxOrdering = 0;

Hope it can help you...

Best regards,
Evgeny Ryabitskiy.

2009/10/2 Evgeny Ryabitskiy <>:
>> Unfortunately there is an empty page at
>> I would also report a broken link on the front page for the Wiki (
>> I would also recomend a FAQ section on the main page which would answer
>> common questions, like "How do I do SELECT count(*) FROM artist WHERE
>> first_name LIKE '%abl%'
> Best way to get any Cayenne Improvement (Documentation or
> Functionality) is to report an issue in JIRA.
> It's not hard.
> Once issue is reported you got every notify about every it's change in
> progress. And the main advantage that since issue reported, it's not
> going to be lost as in this mail list....
> One problem is that JIRA not working properly last few days... hope it
> will be fixed....
>> And that holds true for EJBQLQuery as well does it not? Maybe there should
>> be an advice somewhere in the docs that one must use DataRows as soon as
>> there is just one non-mapped attribute in the query.
> I'v created an JIRA issue for this
> The progress of fix should be faster, if you someday registry in JIRA
> and vote for it... ;)
> Best regards,
> Evgeny Ryabitskiy.

View raw message