Could not build lazy iterator for class of foreign collection member

577 Views Asked by At

I have a simple master-detail, when I query for de master and inspect for the foreign member collection, throw an exception java.lang.IllegalStateException: Could not build lazy iterator for class com.example.entity.detail

List<Master> masters = DBHelper.getMasterDao().queryForAll();

At this point, masters are retrieved fine but at try to access to the foreign member throws the exception.

Class definition

public class Master {

    public Master(){

    }

    @DatabaseField(id = true)
    public int Id;

    @DatabaseField(format = "yyyy-MM-dd'T'HH:mm:ss", dataType = DataType.DATE_STRING)
    public Date CreationDate;

    // Reverse navigation
    @ForeignCollectionField(eager = true)
    public Collection<detail> details;
}

public class Detail{

    @DatabaseField(id = true)
    public long Id;
    @DatabaseField
    public int Month;
    @DatabaseField
    public double Price;
    @DatabaseField
    public double Diff;

    @DatabaseField(canBeNull = true, foreign = true)
    public Master master;
}
1

There are 1 best solutions below

0
Vanheden On

Make sure that you have created all related tables in your SQL database.

This was my mistake when I got this error. I just looked closely at my stack trace and found the issue.