Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA NamedQuery Result(returning partial list of Class fields)
JPA NamedQuery Result [message #503061] Thu, 10 December 2009 17:54 Go to next message
Larry  is currently offline Larry Friend
Messages: 30
Registered: December 2009
Sorry if this is easy question, new to JPA!

I would like to create a named query that returns only a few fields of an Entity.

Something like this "select, from Employee emp".

I would like to get back an instance on Employee with just those fields filled in. Is this possible?? It seems pretty cumbersome to have to use "List<Object[String,int]>" .

Thanks for the help.
Re: JPA NamedQuery Result [message #503107 is a reply to message #503061] Thu, 10 December 2009 21:17 Go to previous message
Doug Clarke is currently offline Doug ClarkeFriend
Messages: 155
Registered: July 2009
Senior Member
You can use a FetchGroup to specify the attributes you want loaded. The entity will then load the rest of its state upon demand.

public List<Employee> fetchGroupExample(EntityManager em) {
Query query = em.createQuery("SELECT e FROM Employee e ORDER BY");

FetchGroup fetchGroup = new FetchGroup();

query.setHint(QueryHints.FETCH_GROUP, fetchGroup);

return query.getResultList();

Previous Topic:Tomcat and eclipseLInk
Next Topic:Selecting data using EmbeddedID
Goto Forum:

Current Time: Thu Apr 26 11:49:36 GMT 2018

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

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