You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Sudheer <su...@gmail.com> on 2010/03/02 05:19:05 UTC

Direct mapping between Named query and Pojo

Is it possible to have ditect mapping between named query and pojo? If not
mapping, is there API to convert named query result to a pojo list?

I am using Cayenne 3.0.

Thanks in advance :).
-- 
View this message in context: http://n3.nabble.com/Direct-mapping-between-Named-query-and-Pojo-tp423239p423239.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Direct mapping between Named query and Pojo

Posted by Sudheer <su...@gmail.com>.
Can someone respond to this? I am in urgency to finish evaluating Cayenne for
my requirement. Thanks in advance.
-- 
View this message in context: http://n3.nabble.com/Direct-mapping-between-Named-query-and-Pojo-tp423239p424021.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Direct mapping between Named query and Pojo

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Mar 3, 2010, at 10:33 AM, Michael Gentry wrote:

> On Tue, Mar 2, 2010 at 11:30 PM, Sudheer <su...@gmail.com>  
> wrote:
>> Assume that named query is on more than one table and has columns  
>> from more
>> than one table. In this case we may not be having dataobject  
>> defined stright
>> from tables. So can I create a dataobject that just maps to named  
>> query?
>
> A DataObject needs to be associated with a single table.

Let me also add that entities can have flattened attributes that can  
span relationships.

Andrus


Re: Direct mapping between Named query and Pojo

Posted by Michael Gentry <mg...@masslight.net>.
On Tue, Mar 2, 2010 at 11:30 PM, Sudheer <su...@gmail.com> wrote:
> Assume that named query is on more than one table and has columns from more
> than one table. In this case we may not be having dataobject defined stright
> from tables. So can I create a dataobject that just maps to named query?

A DataObject needs to be associated with a single table.  Of course,
it can have relationships to other tables.  If you really need to have
a DataObject associated with multiple tables and your database
supports views, then you can create a view that you map to your
DataObject.

> If my query is fixed, I will keep it in datamap and pass the runtime
> parameter values. But I am more interested in dynamic where condition
> constructed on existing named query. For e.g. Take a case of filter on list
> of objects (as mentioned above, object contains columns from mutiple
> tables). After user keys in the filter criteria, I need to constrict a
> dynamic where condition and link to existing named query.

I'm not sure if this really answers your question, but Cayenne by
default will omit (thereby widening the search) portions of the query
that are missing.  If you have:

firstName = $firstName and lastName = $lastName

and you only provide the query with the $lastName substitution
parameter, then Cayenne drops the firstName = $firstName part of the
query for you.

mrg

Re: Direct mapping between Named query and Pojo

Posted by Andrus Adamchik <an...@objectstyle.org>.
There are two options:

1. EJBQL. This supports "compound" results, with each result object  
being an Object[], with each array element corresponding to a separate  
entity or a scalar.
2. DataRows (mentioned already in this thread). Then each row is a map  
that can contain arbitrary data.

Andrus

On Mar 2, 2010, at 11:30 PM, Sudheer wrote:
> Thanks Andrus for the response.
>
> Assume that named query is on more than one table and has columns  
> from more
> than one table. In this case we may not be having dataobject defined  
> stright
> from tables. So can I create a dataobject that just maps to named  
> query?
>
> If my query is fixed, I will keep it in datamap and pass the runtime
> parameter values. But I am more interested in dynamic where condition
> constructed on existing named query. For e.g. Take a case of filter  
> on list
> of objects (as mentioned above, object contains columns from mutiple
> tables). After user keys in the filter criteria, I need to constrict a
> dynamic where condition and link to existing named query.
>
> Hope I did not confuse you :)
> -- 
> View this message in context: http://n3.nabble.com/Direct-mapping-between-Named-query-and-Pojo-tp423239p425390.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>


Re: Direct mapping between Named query and Pojo

Posted by Sudheer <su...@gmail.com>.
Thanks Andrus for the response.

Assume that named query is on more than one table and has columns from more
than one table. In this case we may not be having dataobject defined stright
from tables. So can I create a dataobject that just maps to named query?

If my query is fixed, I will keep it in datamap and pass the runtime
parameter values. But I am more interested in dynamic where condition
constructed on existing named query. For e.g. Take a case of filter on list
of objects (as mentioned above, object contains columns from mutiple
tables). After user keys in the filter criteria, I need to constrict a
dynamic where condition and link to existing named query.

Hope I did not confuse you :)
-- 
View this message in context: http://n3.nabble.com/Direct-mapping-between-Named-query-and-Pojo-tp423239p425390.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Direct mapping between Named query and Pojo

Posted by Andrus Adamchik <an...@objectstyle.org>.
Named queries behave the same way as API-based queries. So you can  
used a named query to get a list of DataObjects:

http://cayenne.apache.org/doc30/namedquery.html

Not clear if this is what you meant by POJOs?

And of course they can also perform updates and EJBQL named queries  
can return lists of scalars, etc.

Andrus


On Mar 1, 2010, at 11:19 PM, Sudheer wrote:

>
> Is it possible to have ditect mapping between named query and pojo?  
> If not
> mapping, is there API to convert named query result to a pojo list?
>
> I am using Cayenne 3.0.
>
> Thanks in advance :).
> -- 
> View this message in context: http://n3.nabble.com/Direct-mapping-between-Named-query-and-Pojo-tp423239p423239.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>