为什么要“将类的实例作为实体存储在数据库中”?
我试图理解 Google Datastore API 其中说:
JDO 在 Java 类上使用注释 描述类的实例如何 存储在数据存储中为 实体,以及实体如何 检索时重新创建为实例 来自数据存储。
我确信这对大多数人来说是一个非常基本的问题。 但我不明白为什么类对象需要存储在数据库中并稍后检索。 为什么不定义您希望应用程序的数据存储区的外观,并根据需要仅存储类属性中的相关数据,而不是存储整个类或始终重复存储相同的属性? 类的实例包含各种信息,在我看来,这些信息不需要在数据库中 - 方法、类变量、实例变量 - 我们在源代码中编写这些内容,并且不需要重现它在数据库中 - 我们只需要存储该类正在操作的某些相关数据。 正确的? 也许我不明白引用的声明是什么意思。 如果我理解有误,请纠正我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google Datastore 不是 SQL Server 或 Oracle 等标准关系数据库。 实体根据其定义进行存储,而不是先创建模式,然后将对象映射到模式的传统方法。 我不认为私有成员或方法与数据一起存储,因此它不像整个对象(包括方法)被序列化到数据存储中。
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.
这正是您引用的实际含义:
您可以使用注释来表示“存储字段 X”、“忽略字段 Y”等。
That is exactly what what you quoted actually means:
You use annotations to say "store field X", "ignore field Y", etc.