Hi,
I have two entities with a many to many relation. First entity is Carrier and the second entity is Folder.
public interface Folder extends Entity {
// other methods
@ManyToMany(through = "getFolder", reverse = "getCarrier", value = CarrierToFolder.class)
Carrier[] getCarriers();
}
public interface Carrier extends Entity {
// others methods
@ManyToMany(through = "getCarrier", reverse = "getFolder", value = CarrierToFolder.class)
public Folder[] getFolders();
}
How is the correct way to recovery all carriers associated with a folder?
I'm trying with this:
@Override
public Folder getFolder(String folderName) {
try {
Folder[] folder = ao.find(Folder.class,
Query.select().where("FOLDER_NAME = ?", folderName ));
if (folder.length != 0) {
return folder[0];
} else {
log.error("The query has not results.");
return null;
}
} catch (Exception ex) {
log.error("Error on get folder: " + ex.getMessage());
}
return null;
}
But, folder[0].getCarriers() always return 01 element.
Thank you.
With inner join example:
Carrier[] carriers = ao.find(Carrier.class,
Query.select()
.alias(Carrier.class, "table1")
.alias(CarrierToFolder.class, "table2")
.join(CarrierToFolder.class, "table1.ID = table2.ID")
.where("table2.ID = ?", folders[0].getID())
);
The array only stay with 1 element. Is there a query limit or restriction?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.