java - 你为什么要 "store instances of the class in the database as entities"?

标签 java database persistence object-persistence

我正在尝试理解 Google Datastore API 中的一行其中说:

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.

我敢肯定,对于大多数人来说,这是一个非常基本的问题。但是我不明白为什么类对象需要存储在数据库中,然后再检索。为什么不定义您希望应用程序的数据存储看起来像什么,并根据需要仅存储类属性中的相关数据,而不是存储整个类或始终重复存储相同的属性?类的实例包含各种信息,在我看来,这些信息不需要在数据库中——方法、类变量、实例变量——我们在源代码中编写这些东西,我们不需要复制它在数据库中——我们只需要存储类正在操作的某些相关数据。正确的?也许我不明白引用的声明是什么意思。如果我理解有误,请指正。

最佳答案

Google Datastore 不是像 SQL Server 或 Oracle 那样的标准关系数据库。实体是根据它们的定义来存储的,而不是先创建模式,然后将对象映射到模式的传统方法。我认为私有(private)成员或方法不会与数据一起存储,因此不会将整个对象(包括方法)序列化到数据存储中。

关于java - 你为什么要 "store instances of the class in the database as entities"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/808815/

相关文章:

java - Jtds SetFloat 在数据库中输入不均匀值(Microsoft Sql Server)

java - 如何在 eclipse RCP 中弄脏编辑器

mysql - 无论如何,我可以使用单个 MySQL 查询在多个表中插入记录吗?

python - 大量字典列表作为磁盘上的查找表

iphone - Core Data 最大存储空间 iPhone

java - 使用模型类 Android 从 Firebase 访问用户信息

java - 用户关闭 JDialog 时的指示

mysql - 在 laravel 中连接表创建重复条目

php - MySQL Process List - 提高性能 - 锁定问题

Symfony2 : do not update a form field if not provided