android – ORMLite不加载子外国字段

我在使用ORMLite 4.42 Android应用程序.我有一个拥有外国领域的实体.这些领域也有外国领域.问题是当我获得根实体的元素时,只会加载第一级的外部字段.其他级别为空.

在数据库上每一个似乎都可以. id是正确的任何帮助?

用模型编辑.

设备模型始终是空的,我按ID查询.但是,如果我查询整个表,那么它可以让我访问所有内容.

表事故

@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;

表设备

@DatabaseField(generatedId=true)
private UUID id;

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

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

表设备类型

@DatabaseField(generatedId=true)
private UUID id;

@DatabaseField(canBeNull=true)
private String type;

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=false)
private EquipmentModelEntity 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.

对,这是设计. ORMLite具体限制了自动刷新子元素的次数.这样做是为了防止巨大的物体树吞咽记忆和反对自我引用的物体.

引用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.

引用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.

如果将maxForeignAutoRefreshLevel增加到更多,那么它将发出额外的查询来刷新元素.

@DatabaseField(foreign=true, foreignAutoRefresh=true, canBeNull=true,
    maxForeignAutoRefreshLevel=3)
private EquipmentEntity equipment;
http://stackoverflow.com/questions/14456609/ormlite-not-loading-child-foreign-fields

转载注明原文:android – ORMLite不加载子外国字段