我正在尝试对以下类执行联接查询:
public class EquipmentCharacteristic {
@DatabaseField(canBeNull = false, foreign = true, uniqueCombo = true)
private Equipment equipment;
@DatabaseField(canBeNull = false, foreign = true, uniqueCombo = true)
private Characteristic characteristic;
...
}
public class Characteristic {
...
}
public class Equipment {
...
}
QueryBuilder的:
QueryBuilder<EquipmentCharacteristic, ?> daoEC = entityDAO.getDAO(
EquipmentCharacteristic.class).queryBuilder();
daoEC.where().eq(EquipmentCharacteristic.EQUIPMENT + "_id", equipment.getId());
QueryBuilder<Characteristic, ?> daoCharacteristic = entityDAO.getDAO(
Characteristic.class).queryBuilder();
return daoEC.join(daoCharacteristic)
.selectRaw(
"EquipmentCharacteristic." + EquipmentCharacteristic.ID,
"EquipmentCharacteristic." + EquipmentCharacteristic.EQUIPMENT + "_" + Equipment.ID,
"EquipmentCharacteristic." + EquipmentCharacteristic.POSSIBLE_VALUES,
"EquipmentCharacteristic." + EquipmentCharacteristic.CHARACTERISTIC + "_" + Characteristic.ID,
"EquipmentCharacteristic." + EquipmentCharacteristic.VALUE,
"Characteristic." + Characteristic.FIXED_VALUE,
"Characteristic." + Characteristic.UNIT,
"Characteristic." + Characteristic.CHARACTERISTIC)
.queryRaw().closeableIterator();
问题是创建的查询与设备连接而不是特征:
SELECT
EquipmentCharacteristic.id,
EquipmentCharacteristic.equipment_id,
EquipmentCharacteristic.possibleValues,
EquipmentCharacteristic.characteristic_id,
EquipmentCharacteristic.value,
Characteristic.fixedValue,
Characteristic.unit,
Characteristic.characteristic
FROM `EquipmentCharacteristic` INNER JOIN `Characteristic` ON `EquipmentCharacteristic`.`equipment_id` = `Characteristic`.`id`
如果我在设备之前将特性参考放在EquipmentCharacteristic中,则问题不会发生。
public class EquipmentCharacteristic {
@DatabaseField(canBeNull = false, foreign = true, uniqueCombo = true)
private Characteristic characteristic;
@DatabaseField(canBeNull = false, foreign = true, uniqueCombo = true)
private Equipment equipment;
...
}
有没有办法告知QueryBuilder应该用于连接的哪个表(类)?
感谢。
答案 0 :(得分:0)
问题是创建的查询与设备连接而不是特征:
我很抱歉,但我无法重现这一点。我已经将以下测试添加到trunk。如果你能弄清楚为什么我的测试工作但代码失败,那将非常有帮助。
https://github.com/j256/ormlite-core/commit/78223c682aa0d7063c095afc0e26b466aeb618af
不幸的是,答案并不多。