ORMLite: Wewnętrzny obiekt DAO ma wartość NULL
Używam ORMLite, próbując użyć klucza ForeignCollectionKey, ale otrzymałem następujący błąd:
Wewnętrzny obiekt DAO ma wartość NULL. LazyCollections nie mogą być używane, jeśli zostały rozszeregowane.
Mam swój obiekt o nazwie Strefa:
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;
}
W klasie wykonuję metodę rekurencyjną, aby uzyskać wszystkie obiekty potomne strefy:
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);
}
}
Kiedy wchodzę po raz pierwszy w moimgetZone
, wszystko idzie dobrze. Potem, kiedy się zapętlęgetZone
aplikacja ulega awarii podczas próby dostępu do strefy podrzędnej:
List<Zone> childList = new ArrayList<Zone>(zone.getZoneChild());
Czy masz jakies pomysły ? Czy moja konstrukcja jest odpowiednia? Dzięki