Syntax of named queries in ebean-orm.xml

486 views
Skip to first unread message

Dennis

unread,
May 30, 2012, 2:28:58 PM5/30/12
to eb...@googlegroups.com
I want to store my sql query in ebean-orm.xml to use it as named query but can't find any example of that xml file or info about its syntax.
Please point me with some link, or I'm searching wrong thing?
Thank you.

Dennis.

Dennis

unread,
May 30, 2012, 7:27:17 PM5/30/12
to eb...@googlegroups.com
Finally I found an answer in com.avaje.ebeaninternal.server.deploy.DeployOrmXml#initialiseNativeQueries().
In case someone will stuck with this too I'll post an example:

orm.xml (in classpath):
<entity-mappings>
    <named-native-query name="calculateCustomerTurnover">
        <query>
            select sum(total_usd) as turnover
            from shipment
            where partner=:partner_id
        </query>
    </named-native-query>
</entity-mappings>

in code:
SqlQuery query = db.createNamedSqlQuery("calculateCustomerTurnover");
query.setParameter("partner_id", customer.getId());
return query.findUnique().getBigDecimal("turnover");
Reply all
Reply to author
Forward
0 new messages