ORMLite不加载子洋田 [英] ORMLite not loading child foreign fields

查看:216
本文介绍了ORMLite不加载子洋田的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ORMLite 4.42 Android应用程式。我有一个实体至极有洋田。这些领域有洋田也。问题是,当我得到的根实体的元素,只有洋田的第一级被加载。其余级别为空。

在数据库中的每个似乎确定。该ID是正确的。任何帮助吗?

修改配车型


该设备型号总是空qhen我通过ID查询。但是,如果我查询整个表,那么它给了我获得的一切。

TABLE事故

  @DatabaseField(generatedId =真)
私人UUID ID;@DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE,canBeNull = FALSE)
私人UserEntity用户;@DatabaseField(dataType的= DataType.DATE,canBeNull = TRUE)
私人日期日期;@DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE,canBeNull = TRUE)
私人EquipmentEntity设备;

TABLE设备

  @DatabaseField(generatedId =真)
私人UUID ID;@DatabaseField(canBeNull =假,唯一= TRUE)
私人字符串序列;@DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE,canBeNull = FALSE)
私人EquipmentTypeEntity类型;

TABLE设备TYPE

  @DatabaseField(generatedId =真)
私人UUID ID;@DatabaseField(canBeNull =真)
私人字符串类型;@DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE,canBeNull = FALSE)
私人EquipmentModelEntity模型;

TABLE设备模型

  @DatabaseField(generatedId =真)
私人UUID ID;@DatabaseField(canBeNull = FALSE)
私人字符串模式;


解决方案

  

我使用ORMLite 4.42 Android应用程式。我有一个实体至极有洋田。这些领域有洋田也。问题是,当我得到的根实体的元素,只有洋田的第一级被加载。其他人水平是零。


对,这是由设计。 ORMLite 特别限制的次数就自动刷新的子元素。这样做是为了防止的巨大的对象树吞咽的记忆和对自我指涉的对象。

要为报价 foreignAutoRefresh


  

请注意:为了防止递归,有几个地方是自动刷新受到了限制。如果你是自动刷新本身有场foreignAutoRefresh类设置为true,或者如果您自动刷新类与外国的收集,在这两种情况下产生的字段将被设置为null,并且不会自动刷新。您可以随时拨打直接,如果你需要它的领域刷新。


  
  

请注意:如果你有一个自动刷新的字段是一个对象,它也有一个自动刷新场,您可能需要调整maxForeignAutoRefreshLevel值。见下文。


要在文档引述 maxForeignAutoRefreshLevel


  

这可被用于设置级别的最大数目来配置异物。例如,如果你有有最好的答案的洋场的问题,答案有一个洋场到相应的问题,则配置来回可以得到很大。这是尤其当你查找它可能会导致一个无限循环的问题自动刷新领域的问题。默认情况下,只有ORMLite经过2的水平,但可以将其减少到1(0是无效的),或者增加。越高越数据库事务发生的次数,当你在你的问题加载。


如果您增加 maxForeignAutoRefreshLevel 更那么它会发出额外的查询刷新的元素。

  @DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE,canBeNull = TRUE,
    maxForeignAutoRefreshLevel = 3)
私人EquipmentEntity设备;

I'm using ORMLite 4.42 for an Android app. I have an entity wich has foreign fields. These fields have foreign fields too. The problem is that when i get an element of the root entity, only the first level of foreign fields are loaded. The others levels are null.

On the database every seems ok. The id is correct. Any help?

Edit with models.


The Equipment model is always null qhen I query by ID. But if I query the whole table, then it gives me access to everything.

TABLE INCIDENT

@DatabaseField(generatedId=true)
private UUID id;

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=false)
private UserEntity user;

@DatabaseField(dataType = DataType.DATE, canBeNull=true)
private Date date;

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=true)
private EquipmentEntity equipment;

TABLE EQUIPMENT

@DatabaseField(generatedId=true)
private UUID id;

@DatabaseField(canBeNull=false, unique=true)
private String serial;

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=false)
private EquipmentTypeEntity type;

TABLE EQUIPMENT TYPE

@DatabaseField(generatedId=true)
private UUID id;

@DatabaseField(canBeNull=true)
private String type;

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=false)
private EquipmentModelEntity model;

TABLE EQUIPMENT MODEL

@DatabaseField(generatedId=true)
private UUID id;

@DatabaseField(canBeNull=false)
private String model;

解决方案

I'm using ORMLite 4.42 for an Android app. I have an entity wich has foreign fields. These fields have foreign fields too. The problem is that when i get an element of the root entity, only the first level of foreign fields are loaded. The others levels are null.

Right, this is by design. ORMLite specifically limits the number of times it auto-refreshes a sub-element. This was done to protect against huge object trees swallowing memory and against self referential objects.

To quote the docs for foreignAutoRefresh:

NOTE: To protect against recursion, there are a couple of places were auto-refreshing has been limited. If you are auto-refreshing a class that itself has field with foreignAutoRefresh set to true or if you are auto-refreshing a class with a foreign collection, in both cases the resulting field will be set to null and not auto-refreshed. You can always call refresh on the field directly if you need it.

NOTE: If you have an auto-refreshed field that is an object that also has an auto-refreshed field, you may want to tune the maxForeignAutoRefreshLevel value. See below.

To quote from the docs for maxForeignAutoRefreshLevel:

This can be used to set the maximum number of levels to configure foreign objects. For example, if you have a Question which has an foreign field of the best Answer, and the Answer has an foreign field to the corresponding question, then the configuration back and forth can get large. This is especially a problem with auto-refreshed fields when you lookup the Question it could cause an infinite loop. By default, ORMLite only goes through 2 levels but you can decrease it to 1 (0 is not valid) or increase it. The higher the number the more database transactions happen when you load in your Question.

If you increase the maxForeignAutoRefreshLevel to be more then it will issue the extra queries to refresh the elements.

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=true,
    maxForeignAutoRefreshLevel=3)
private EquipmentEntity equipment;

这篇关于ORMLite不加载子洋田的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆