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;
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
:To quote from the docs for
maxForeignAutoRefreshLevel
:If you increase the
maxForeignAutoRefreshLevel
to be more then it will issue the extra queries to refresh the elements.