Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » FetchGroup help(How to setup/use FetchGroup)
FetchGroup help [message #504053] Wed, 16 December 2009 12:58 Go to next message
Larry  is currently offline Larry
Messages: 30
Registered: December 2009
Member
Really stuggling with the FetchGroup. Seems so easy, but keep getting errors!!

I have an Address object setup as a JPA Entity. I have a couple of named queries also defined. Both queries return a few of the columns. I would like to return the Address object, not a list of Objects for each column. I am using the FetchGroup so only the columns I specified in the query are returned.

This is what I have:

FetchGroup grp = new FetchGroup();
grp.addAttribute("amt_paid");
ReadAllQuery q = new ReadAllQuery(DrsDrPay.class);
q.setFetchGroup(grp);
q.executeDatabaseQuery();

I am using Eclipse Galileo, eclipseLink 1.1.2

Thanks
Re: FetchGroup help [message #504178 is a reply to message #504053] Thu, 17 December 2009 10:12 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What error are you getting?

James : Wiki : Book : Blog : Twitter
Re: FetchGroup help [message #504205 is a reply to message #504178] Thu, 17 December 2009 11:41 Go to previous messageGo to next message
Larry  is currently offline Larry
Messages: 30
Registered: December 2009
Member
This is the error msg:

Exception in thread "main" java.lang.NullPointerException
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute DatabaseQuery(ObjectLevelReadQuery.java:897)
at DBManager.doFetchGroup(DBManager.java:79)
at DBManager.main(DBManager.java:118)


Thanks
Re: FetchGroup help [message #504234 is a reply to message #504205] Thu, 17 December 2009 14:13 Go to previous message
Larry  is currently offline Larry
Messages: 30
Registered: December 2009
Member
I just realized that the ReadAllQuery that I am using really isn't connected to anything for the DB info. Where does it get the connection to DB??? So I know I did something wrong!

I saw some examples on the EclipseLink site that uses a Descriptor. Not sure how you get the descriptor instance/object. This is the example for setting up a default fetch-group! It's the reason you need the descriptor.

******************************************
// at the descriptor level
FetchGroup group = new FetchGroup("nameOnly");
group.addAttribute("firstName");
group.addAttribute("lastName");
employeeDescriptor.getFetchGroupManager().addFetchGroup(grou p);
// set the default fetch group
employeeDescriptor.getFetchGroupManager().setDefaultFetchGro up(group);

// when query1 is executed, the default fetch group applies
ReadAllQuery query1 = new ReadAllQuery(Employee.class);

// when query2 is executed, the default fetch group does not apply
ReadAllQuery query2 = new ReadAllQuery(Employee.class);
query2.setShouldUsedefaultFetchGroup(false);

*******************************************

I also saw this one which is the way I set it up initially:
**********************************************************
// dynamic fetch group query
ReadAllQuery query = new ReadAllQuery(Employee.class);
FetchGroup group = new FetchGroup("nameAndSalary");
group.addAttribute("firstName");
group.addAttribute("lastName");
group.addAttribute("salary");
query. setFetchGroup(group);
************************************************************ *

No descriptor here so same problem exists - how do you execute it. I just jused the "query.executeDatabase()" method. I don't believe this is correct because it doesn't have access to the DB connection(????). I did see an example a little bit ago that used the session object to execute. I was able to get the defaultSession, but still got an error

This is what I executed:
SessionManager.getManager().getDefaultSession().executeQuery (q);

This is the error:
************************************************************ ******
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-7095] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The sessions.xml resource [sessions.xml] was not found on the resource path. Check that the resource name/path and classloader passed to the SessionManager.getSession are correct. The sessions.xml should be included in the root of the applications deployed jar, if the sessions.xml is deployed in a sub-directory in the applications jar ensure that the correct resource path using "/" not "\" is used.
at org.eclipse.persistence.exceptions.ValidationException.noSes sionsXMLFound(ValidationException.java:810)
at org.eclipse.persistence.sessions.factories.XMLSessionConfigL oader.loadDocument(XMLSessionConfigLoader.java:341)
at org.eclipse.persistence.sessions.factories.XMLSessionConfigL oader.loadDocument(XMLSessionConfigLoader.java:320)
at org.eclipse.persistence.sessions.factories.XMLSessionConfigL oader.load(XMLSessionConfigLoader.java:234)
at org.eclipse.persistence.sessions.factories.SessionManager.ge tSession(SessionManager.java:395)
at org.eclipse.persistence.sessions.factories.SessionManager.ge tSession(SessionManager.java:190)
at org.eclipse.persistence.sessions.factories.SessionManager.ge tDefaultSession(SessionManager.java:108)
at DBManager.doFetchGroup(DBManager.java:83)
at DBManager.main(DBManager.java:123)
************************************************************ **********

wrong session????

Any help would be great!!!

Thanks


Previous Topic:Bug with IndirectMap?
Next Topic:Cannot find entities classes when packaged in another bundle than bundle containing persistence.xml
Goto Forum:
  


Current Time: Wed Jul 30 13:14:19 EDT 2014

Powered by FUDForum. Page generated in 0.09367 seconds