Question

I'm trying to understand a line from the Google Datastore API which says:

JDO uses annotations on Java classes to describe how instances of the class are stored in the datastore as entities, and how entities are recreated as instances when retrieved from the datastore.

I'm sure this is a very basic question for most people. But I don't understand why the class object needs to be stored in the database and later retrieved. Why not instead define what you want the datastore to look like for your application and store only relevant data from your class properties as needed instead of storing the entire class or always storing the same properties repeatedly? The instance of the class contains all kinds of information that, it seems to me, does not need to be in the database - methods, class variables, instance variables - we write that stuff in our source code and we don't need to reproduce it in the database - we only need certain relevant data that the class is operating on to be stored. Right? Maybe I'm not understanding what is meant by the quoted statement. Please correct me if I have misunderstood.

Was it helpful?

Solution

The Google Datastore is not a standard relational database like SQL Server or Oracle. Entities are stored based on their definition, rather than the traditional method of creating a schema first, then mapping an object to the schema. I don't think private members or methods are stored along with the data, so it's not like the entire object, including methods, is serialized into the Datastore.

OTHER TIPS

Why not instead define what you want the datastore to look like for your application and store only relevant data from your class properties as needed instead of storing the entire class or always storing the same properties repeatedly?

That is exactly what what you quoted actually means:

JDO uses annotations on Java classes to describe how instances of the class are stored in the datastore as entities, and how entities are recreated as instances when retrieved from the datastore.

You use annotations to say "store field X", "ignore field Y", etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top