You could do that, but personally, I tend to be wary of putting computed data into the entity types themselves. You're in the grey area in the question of when to use your domain model as a DTO graph vs. creating a separate set of DTOs.
-Patrick -- Patrick Linskey BEA Systems, Inc. _______________________________________________________________________ Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. > -----Original Message----- > From: Tom Mutdosch [mailto:[EMAIL PROTECTED] > Sent: Friday, February 23, 2007 1:58 PM > To: open-jpa-dev@incubator.apache.org > Subject: Re: possible to write a JPA Query to that filters > both an Entity and its relationship entities? > > Hi Patrick, > Thanks for the query suggestion. I guess what I was > initially thinking > of doing was incorrect in that JPA doesn't really give me a "view" of > what I want. That is, I can never get a Department object > containing a > list of filtered Employees. A JPA object returned from a query is > always going to be an exact representation of the database. So your > Department object is always going to contain all of the > Employees in its > relationship. > > So like you mentioned, I can still get all the information using one > query, and then just process those results as I want them. I imagine > that this would entail some sort of wrapper bean that would house the > Department and the filtered list of Employees. Or what if I added a > regular method to my Department entity called > getFilterEmployees() which > would return a List that I populated with the filtered > results from my > query? Does that seem like a reasonable thing to do -- if I > didn't want > to deal with a wrapper object but still have all of my desired data > captured by a single Entity? > > Thanks > Tom > > > Patrick Linskey wrote: > > It is, but it doesn't buy you much in this situation -- the > oldTimers > > collection in your example won't be filtered to just the > ones that are > > old. It'll be all the employees in the dept. > > > > -Patrick > > > > >