google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Allow loading an entity of the same name into multiple POJO classes (to scope what gets retrieved from datastore) #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be great to be able to define multiple entities having the same name 
but with different properties so the data retrieved can be scoped.

For example,

@Entity(name="thing")
public class Thing {
   // all properties that this thing has
}

@Entity(name="thing")
public class ThingDTO {
  // only the properties that I want to display
  // when showing this data in a list
}

Original issue reported on code.google.com by joe...@gmail.com on 22 Jun 2011 at 12:12

GoogleCodeExporter commented 9 years ago
Whoops!  I meant to file this as an enhancement but can't change it now.  Sorry.

Original comment by joe...@gmail.com on 22 Jun 2011 at 12:13

GoogleCodeExporter commented 9 years ago
Just today, we spoke about such a feature. Our use case goes as follows:
We have one kind of entity, and two ways to access it:
 - "Preview" object with just the basic properties (cheap to send lists of those objects over the network)
 - "Full" object containing all properties (expensive to send, queried individually on-demand)

My first thought was the same: one kind in the Datastore and two classes to 
access it.

Any idea how we can model this with Objectify?

Original comment by mar...@greenrobot.de on 22 Jun 2011 at 4:20

GoogleCodeExporter commented 9 years ago
The "standard" way of modeling this is to simply construct the new DTO from the 
data loaded in the entity pojo.  I have some misgivings about having a partial 
entity since someone could accidentally save it... the alternate would have to 
be non-saveable.  But I see the point.

Original comment by lhori...@gmail.com on 22 Jun 2011 at 4:43

GoogleCodeExporter commented 9 years ago
Right, copying the selection of properties into a DTO is probably the best way 
to do it.

Hmm, partial entities would not improve performance, I guess, because Google's 
data store returns the full data anyway, right?

Original comment by mar...@greenrobot.de on 22 Jun 2011 at 5:07

GoogleCodeExporter commented 9 years ago
I may be naive here.  I created this feature request because I assumed that the 
specific fields can be requested when making an entity request (only because 
that flexibility is available with Amazon SimpleDB).  If this is not the case 
than this feature request doesn't add too much value.

Original comment by joe...@gmail.com on 22 Jun 2011 at 5:11

GoogleCodeExporter commented 9 years ago
Google's datastore always returns the full Entity, all properties.  The only 
thing you would be shaving off is the overhead of Objectify translating those 
properties from an Entity to the fields of your POJO - but this is a very, very 
tiny sliver of the cost of loading an entity.

If the goal of this is efficiency, it really isn't worth it.

Original comment by lhori...@gmail.com on 22 Jun 2011 at 5:15

GoogleCodeExporter commented 9 years ago
Thanks for confirming. For me, there's no more need for this enhancement.

Original comment by mar...@greenrobot.de on 22 Jun 2011 at 5:23

GoogleCodeExporter commented 9 years ago
Agreed.  I'm going to put a request for this with app engine directly which I'm 
sure they'll ignore :)  Thanks.

Original comment by joe...@gmail.com on 22 Jun 2011 at 5:25

GoogleCodeExporter commented 9 years ago
Ok, closing this as WontFix.  If someone really wants this feature sometime 
later, it can be re-opened.

Original comment by lhori...@gmail.com on 22 Jun 2011 at 5:30

GoogleCodeExporter commented 9 years ago
It would be great if anyone who is interested in this feature could start this: 
http://code.google.com/p/googleappengine/issues/detail?id=5233

Original comment by joe...@gmail.com on 22 Jun 2011 at 5:38

GoogleCodeExporter commented 9 years ago
You got my star. Thanks for opening the issue - is this really the first time 
someone requested it? Unbelievable... ;)

Once App Engine is capable of doing that, we should reopen the ticket. :)

Original comment by mar...@greenrobot.de on 22 Jun 2011 at 5:51

GoogleCodeExporter commented 9 years ago
To be honest, I'm not sure that feature request is a great one.  It might (or 
might not) make a big difference if you have a lot of blob data you don't need 
to select.  This is something that presumably Google has measured, and they 
have judged it as not sufficiently valuable in exchange for the significant 
amount of complexity it introduces.

I dunno.

Original comment by lhori...@gmail.com on 22 Jun 2011 at 6:47