为什么要“将类的实例作为实体存储在数据库中”?

发布于 2024-07-19 05:21:48 字数 545 浏览 9 评论 0原文

我试图理解 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝在阴天搁浅。 2024-07-26 05:21:48

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.

无边思念无边月 2024-07-26 05:21:48

为什么不定义您希望应用程序的数据存储区的外观,并根据需要仅存储类属性中的相关数据,而不是存储整个类或始终重复存储相同的属性?

这正是您引用的实际含义:

JDO 使用 Java 类上的注释来描述类的实例如何作为实体存储在数据存储中,以及从数据存储中检索实体时如何将实体重新创建为实例。

您可以使用注释来表示“存储字段 X”、“忽略字段 Y”等。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文