android – ORMLite不加载子外国字段

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

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




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;


private UUID id;

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

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


private UUID id;

private String type;

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


private UUID id;

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.


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.


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

转载注明原文:android – ORMLite不加载子外国字段 - 代码日志