ORMLite: el objeto DAO interno es nulo
Estoy usando ORMLite, tratando de usar ForeignCollectionKey pero obtuve el siguiente error:
El objeto DAO interno es nulo. LazyCollections no se puede utilizar si se han deserializado.
Tengo mi objeto llamado Zona:
public class Zone implements Serializable {
private static final long serialVersionUID = 1L;
public static final String ZONE_ID = "id";
public static final String ZONE_PARENT_ID = "parentZoneId";
@DatabaseField(generatedId=true)
private int id;
@DatabaseField()
String name;
@DatabaseField(foreign=true, foreignAutoRefresh = true)
Zone parentZone;
@ForeignCollectionField(foreignFieldName = "parentZone", eager = true)
private ForeignCollection<Zone> zoneChild;
public Zone() {
// TODO Auto-generated constructor stub
}
public ForeignCollection<Zone> getZoneChild() {
return zoneChild;
}
public void setZoneChild(ForeignCollection<Zone> zoneChild) {
this.zoneChild = zoneChild;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
En una clase, estoy haciendo un método recursivo para obtener todos los objetos secundarios de mi zona:
public void getZone(Zone zone, Dao<Zone, Integer> tempZoneDao){
ZoneListEntity zoneEntity = new ZoneListEntity();
zoneEntity.setName(zone.getName());
zoneEntity.setNiveau(0);
zoneEntity.setZone(zone);
mainZoneList.add(zoneEntity);
List<Zone> childList = new ArrayList<Zone>(zone.getZoneChild());
//set rootZone's children as ZoneListEntity
for(Zone currentZone : childList){
ZoneListEntity zoneGroup = new ZoneListEntity();
zoneGroup.setName(currentZone.getName());
zoneGroup.setZone(currentZone);
System.out.println("Zone : "+currentZone.getName());
getZone(currentZone, tempZoneDao);
}
}
Cuando entro por primera vez en migetZone
, todo va bien. Entonces cuando hago un buclegetZone
La aplicación se bloquea al intentar acceder a la zona secundaria:
List<Zone> childList = new ArrayList<Zone>(zone.getZoneChild());
Tienes alguna idea ? ¿Mi modelo de construcción es correcto? Gracias