Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPQL and partial attributes
JPQL and partial attributes [message #385305] Tue, 27 January 2009 12:47 Go to next message
Ana Tatavu is currently offline Ana Tatavu
Messages: 10
Registered: July 2009
Junior Member
Hi,
I would like to know if is possible to retrieve just some attributes of an
object using JPQL queries.
I tried to use something like:
Select SELECT j.jobStatus,j.application,j.server FROM JobEntity j WHERE
(j.application like 'application%' and j.server = 'server1')
In both EclipseLink and Derby logs I can see that all the columns, not
just the ones in the JPQL select are retrieved.


Ana
Re: JPQL and partial attributes [message #385309 is a reply to message #385305] Tue, 27 January 2009 13:08 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This is possible, and the JPQL you included should work. This JPQL should
return an Object[] of the raw values. Please include the query code and
SQL that was generated.

If you want to get objects back instead of the values you could use a
constructor query, or use EclipseLink fetch-group support.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: JPQL and partial attributes [message #385311 is a reply to message #385309] Tue, 27 January 2009 13:26 Go to previous messageGo to next message
Ana Tatavu is currently offline Ana Tatavu
Messages: 10
Registered: July 2009
Junior Member
ReadAllQuery query = new ReadAllQuery(AutoSysJob.class);
query.setJPQLString("SELECT job.jobName FROM AutoSysJob job "
+ "WHERE (job.jobName like 'job%' and job.server =
'server1')");

Object listJobs = read(query);
Where "read":
ClientSession cs = getEntityManager().getServerSession()
.acquireClientSession();
try
{
List<?> results = null;
...
results = (List<?>)cs.executeQuery(query);
}...

Generated SQL(eclipse link log)
[EL Fine]: 2009.01.27
08:21:10.187--ServerSession(33397577)--Connection(11819817)- -Thread(Thread[main,5,main])--SELECT
wcc_id, server_type, job_name, job_status, job_type, owner, preds, server,
as_lineage, as_appl, box_name, box_joid, exit_code, as_group, joid,
last_end_stamp, last_start_stamp, next_stamp, ntry, run_mach, run_num,
status_stamp, target_mach, timezone, def_mod, del FROM m_job WHERE
(((job_name LIKE job%) AND (server = server1)) AND (server_type = A))


Ana
Re: JPQL and partial attributes [message #385312 is a reply to message #385311] Tue, 27 January 2009 16:03 Go to previous messageGo to next message
Ana Tatavu is currently offline Ana Tatavu
Messages: 10
Registered: July 2009
Junior Member
If I set the partialAttributes on ReadAllQuery, instead as part of the
JPQL string it will fetch the just the partial ones.


Ana
Re: JPQL and partial attributes [message #385405 is a reply to message #385311] Wed, 28 January 2009 12:34 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Why are you using the Session and ReadAllQuery?

You should just do,

List results = getEntityManager().createQuery("SELECT job.jobName FROM
AutoSysJob job WHERE (job.jobName like 'job%' and job.server =
'server1')").getResultList();

In the native API, ReadAllQuery only returns objects, if you use a
ReportQuery, you can select data, but you should not need to use the
native API.

In JPA you can also select the entire object and set a FetchGroup on the
query to only fetch some of the attributes.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:Native Query issues
Next Topic:Caching or Isolations-Level Problem?
Goto Forum:
  


Current Time: Sat Nov 01 03:58:11 GMT 2014

Powered by FUDForum. Page generated in 0.01661 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software