Andrea Sprega
Andrea Sprega

Reputation: 2271

ORMLite for Android doesn't autorefresh foreign object using foreignAutoRefresh

Here's my problem: I have different entities linked to others up to a nesting depth of 3. All my foreign fields in every object are annotated with

@DatabaseField(foreign = true, foreignAutoRefresh = true)

But only up to a nesting depth of 2 I get actual autoRefreshed foreign objects.

For example, if I query for an A entity and then I do:

A.getB().getC().getD()

for entities B and C I already have all the fields, while for entity D I only have the ID fetched and I need to call the dao.refresh() method in order to fetch all of the D fields. Is it a limitation? I can't find anything about it on the documentation.

Upvotes: 4

Views: 3655

Answers (2)

Gray
Gray

Reputation: 116908

Edit:

So after creating some better unit tests and looking into this more, this turned out to be a bug. ORMLite was handling the maxForeignAutoRefreshLevel setting in the @DatabaseField annotation incorrectly. Right now (as you seem to have figured out looking at your answer) you need to add a foreignAutoRefresh = true and maxForeignAutoRefreshLevel = 3 to the C field in your B object and the D field in the C object as well. That should fix it.

I created the following bug report:

https://sourceforge.net/tracker/?func=detail&aid=3530801&group_id=297653&atid=1255989

I've fixed the problem in trunk and I've started the process of pushing out version 4.41. It's been a while since the last release and this is as good a time as any.

Upvotes: 5

Andrea Sprega
Andrea Sprega

Reputation: 2271

I solved the issue by adding the annotation attribute maxForeignAutoRefreshLevel = 3 on the C entity, and D gets now refreshed.

The strange thing is that I didn't need to set maxForeignAutoRefreshLevel in neither A, B or D.

Another detail is that if I set to 2 the level for the C entity, D doesn't get refreshed anymore. Seems like the maxForeignAutoRefreshLevel = 3 gets applied from the C entity to the "starting" entity, in my case A.

Upvotes: 3

Related Questions