gpt4 book ai didi

java - 如何在 App Engine 数据存储区中将 'int' Java 模型属性设置为其原始未设置状态而不是零?

转载 作者:行者123 更新时间:2023-12-01 19:16:54 25 4
gpt4 key购买 nike

代表数据存储实体的 Java 模型类的属性之一由 int 值表示:

int trackedUserId;

该值在应用程序执行过程中设置为特定的用户 ID。然后在其他时候我想将其重置为由空值表示的原始未设置状态。但我能看到重置它的唯一方法是将其设置为零值。 JDO 中是​​否有其他方法可以将属性重置为其未设置状态?

最佳答案

int 是一个原始值,因此不能将其设置为null。根据 JDO 文档,here :

If a datastore entity is loaded into an object and doesn't have a property for one of the object's fields and the field's type is a nullable single-value type, the field is set to null. When the object is saved back to the datastore, the null property becomes set in the datastore to the null value. If the field is not of a nullable value type, loading an entity without the corresponding property throws an exception. This won't happen if the entity was created from the same JDO class used to recreate the instance, but can happen if the JDO class changes, or if the entity was created using the low-level API instead of JDO.

如果您要创建一条包含 int 字段的新记录,并且未指定值,则该字段将使用 Java 的默认值,即 0。

关于java - 如何在 App Engine 数据存储区中将 'int' Java 模型属性设置为其原始未设置状态而不是零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6219785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com