Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » query a subpart of complex graph and get a smallest object (query jpa)
query a subpart of complex graph and get a smallest object [message #989614] Thu, 06 December 2012 23:19 Go to next message
J LM is currently offline J LMFriend
Messages: 11
Registered: December 2012
Junior Member
Hi everyone,
I need some advice about querying a complex graph of entities in order to return a simple object.

Assume I have a Customer which has a onetoone to a person entity which has too a onetoone to an address entity. Each of those entities have their own fields.
I need only 2 fields : the name of the customer and the zipcode of the address but not the other fields (I didn't mention that the Customer owns other relations to other types of entities)

My need is just for readonly.

The number of Customers is really huge and I must get those 2 informations really quick. I must avoid pre-caching but my question is more general.

Is it possible to use something as projections, fetch groups or something else to get those 2 fields to a single object different from the graph of the Customer entity ? How ? Could it be JPA2 compliant ?

I could use SQL as I see how to do this in sql but it would mean coupling a sql query to physical tables that are already defined in my mappings of entities. So will need to maintain the two if a change must occur on the tables.
I could create a view in db this would mean too to maintain the sql query behind the view.

Re: query a subpart of complex graph and get a smallest object [message #990294 is a reply to message #989614] Tue, 11 December 2012 18:10 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can do this in JPQL.

Select, from Customer c join c.person p join p.address a

James : Wiki : Book : Blog : Twitter
Previous Topic:xsd:Any, marshalling, and escaping
Next Topic:EQL / JPQL Operator -datepart- Usage
Goto Forum:

Current Time: Fri May 25 03:39:45 GMT 2018

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

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

Back to the top