android - Fetching objects with Collections -
i'm trying list objects have inner collection. can save , retrieve objects fine, when do:
parentrepo.findall()
only last object has it's child object listed, others has empty collection.
parent model
@foreigncollectionfield(eager = false) private collection<child> childs;
child model
@databasefield(foreign=true,foreignautorefresh=true) private parent parent;
eager true or false doesn't make difference. if query child , parent, can it's children well. missing?
edit:
it's working modeling made. mistake need many-to-many relation between parent , child. made quick research , need intermediate model achieve this. i'll close question , try made many-to-many relation between models.
i solve many-to-many relationships this: example ongoing project. have many-to-many relationship between preparation , glidewax. solve use thee classes: preparation, glidewax , preparationglidewax. preparationglidewax represents connections between the other classes, way solve many-to-many relationships table "link" between tables in relationship. can see gripwax , structure has many-to_many relationship preparation. here code:
glidewax.java
@databasetable(tablename = "glide_waxes") public class glidewax { @databasefield(id = true) private int id; @databasefield(canbenull = false) private string name; @databasefield private string description; @databasefield(canbenull = false) private int inuse; @databasefield(foreign=true) private waxbrand waxbrand; @databasefield(foreign=true) private glidewaxtype glidewaxtype; @foreigncollectionfield private foreigncollection<preparationglidewax> preparationglidewaxes; @foreigncollectionfield private foreigncollection<testsessionglidewax> testsessionglidewaxes; public glidewax() { } public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public int getinuse() { return inuse; } public void setinuse(int inuse) { this.inuse = inuse; } public waxbrand getwaxbrand() { return waxbrand; } public void setwaxbrand(waxbrand waxbrand) { this.waxbrand = waxbrand; } public glidewaxtype getglidewaxtype() { return glidewaxtype; } public void setglidewaxtype(glidewaxtype glidewaxtype) { this.glidewaxtype = glidewaxtype; } public foreigncollection<preparationglidewax> getpreparationglidewaxes() { return preparationglidewaxes; } public void setpreparationglidewaxes(foreigncollection<preparationglidewax> preparationglidewaxes) { this.preparationglidewaxes = preparationglidewaxes; } public foreigncollection<testsessionglidewax> gettestsessionglidewaxes() { return testsessionglidewaxes; } public void settestsessionglidewaxes(foreigncollection<testsessionglidewax> testsessionglidewaxes) { this.testsessionglidewaxes = testsessionglidewaxes; }
}
preparation.java
@databasetable(tablename = "preparations") public class preparation { @databasefield(generatedid=true) private int id; @foreigncollectionfield private foreigncollection<preparationglidewax> preparationglidewaxes; @foreigncollectionfield private foreigncollection<preparationgripwax> preparationgripwaxes; @foreigncollectionfield private foreigncollection<preparationstructure> preparationstructures; @databasefield(foreign=true, canbenull = false) private skipair skipair; @databasefield(foreign=true, canbenull = false) private skitester skitester; @databasefield(foreign=true) private rfid rfid; @databasefield(foreign=true, canbenull = false) private testsession testsession; @foreigncollectionfield private foreigncollection<measurement> measurements; public preparation() { } public int getid() { return id; } public void setid(int id) { this.id = id; } public foreigncollection<preparationglidewax> getpreparationglidewaxes() { return preparationglidewaxes; } public void setpreparationglidewaxes(foreigncollection<preparationglidewax> preparationglidewaxes) { this.preparationglidewaxes = preparationglidewaxes; } public foreigncollection<preparationgripwax> getpreparationgripwaxes() { return preparationgripwaxes; } public void setpreparationgripwaxes(foreigncollection<preparationgripwax> preparationgripwaxes) { this.preparationgripwaxes = preparationgripwaxes; } public foreigncollection<preparationstructure> getpreparationstructures() { return preparationstructures; } public void setpreparationstructures(foreigncollection<preparationstructure> preparationstructures) { this.preparationstructures = preparationstructures; } public skipair getskipair() { return skipair; } public void setskipair(skipair skipair) { this.skipair = skipair; } public skitester getskitester() { return skitester; } public void setskitester(skitester skitester) { this.skitester = skitester; } public rfid getrfid() { return rfid; } public void setrfid(rfid rfid) { this.rfid = rfid; } public testsession gettestsession() { return testsession; } public void settestsession(testsession testsession) { this.testsession = testsession; }
}
preparationglidewax.java
@databasetable(tablename = "preparation_glide_wax") public class preparationglidewax { @databasefield(generatedid=true) private int id; @databasefield(canbenull = false) private int layer; @databasefield(foreign=true, canbenull = false) private glidewax glidewax; @databasefield(foreign=true, canbenull = false) private preparation preparation; public preparationglidewax() { } public int getid() { return id; } public void setid(int id) { this.id = id; } public int getlayer() { return layer; } public void setlayer(int layer) { this.layer = layer; } public glidewax getglidewax() { return glidewax; } public void setglidewax(glidewax glidewax) { this.glidewax = glidewax; } public preparation getpreparation() { return preparation; } public void setpreparation(preparation preparation) { this.preparation = preparation; }
}
Comments
Post a Comment