If you really want to use Cayenne for the power it gives you, rather than 
writing SQL, I recommend you work your way through the tutorials. Yes, you can 
use SQLTemplate. No, that's probably not what you want to do here.

At its heart, your query is just um.ID = 112. Start by making that work in 
Cayenne using a simple select query. Just fetch one um object. And then follow 
the relations from that object to the other objects and properties you need.

resultUM.getUA().getRole()

And remember, that rarely in Cayenne will you want to fetch or query on primary 
keys. Yes, it will sometimes be needed, but mostly you let Cayenne handle that 
for you behind the scenes.


Ari



On 13/12/12 6:14pm, Sampath Uppula wrote:
Hi John,
Thanks for the reply.
For the below query, can you provide a sample using SQLTemplate?

1. how to use the SQLTemplate to execute the below query?
SELECT um.ID,
        um.FIRST_NAME,
        um.LAST_NAME,
        ua.ROLE_ID,
        tt.TASK_ASSIGNED_DATE,
        tt.TASK_CLOSED_DATE,
        tt.TASK_MASTER_ID
   FROM t_user_master um,
        t_user_allocation_details ua,
        t_task_assignment_detail ta,
        t_task_transaction_detail tt
  WHERE     um.ID = ua.USER_ID
        AND ta.USER_ID = um.ID
        AND ta.TASK_TRANSACTION_ID = tt.ID
        AND um.ID = 112;
2. how to read the data from the result set or List?

Appreciate your help.

Thanks,
Sampath Uppula



-----Original Message-----
From: John Huss [mailto:johnth...@gmail.com]
Sent: Thursday, December 13, 2012 2:50 AM
To: user@cayenne.apache.org
Subject: Re: Problem in fetching the data from multiple tables with 
relationships.

I'm not really sure what your question is.  Cayenne will fetch all of the
fields that are modeled and turn them into objects.  And you can add
prefetching paths to your SelectQuery to pre-fetch the related objects,
otherwise they will be loaded when accessed.  If you want to write your own
SQL and get a HashMap of the data you can use SQLTemplate instead of
SelectQuery.

John

============================================================================================================================Disclaimer:
  This message and the information contained herein is proprietary and confidential and subject to the Tech Mahindra policy 
statement, you may review the policy at <a 
href="http://www.techmahindra.com/Disclaimer.html";>http://www.techmahindra.com/Disclaimer.html</a> 
externally and <a 
href="http://tim.techmahindra.com/tim/disclaimer.html";>http://tim.techmahindra.com/tim/disclaimer.html</a>
 internally within Tech 
Mahindra.============================================================================================================================


--
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Reply via email to