我有一个客户端 bean ,
@DatabaseField(columnName = "client_id",generatedId = true,useGetSet = true)
private Integer clientId;
@DatabaseField(columnName = "client_nom",useGetSet = true)
private String clientNom;
@DatabaseField(columnName = "city_id",foreign = true,useGetSet = true)
private City city;
和一颗城市豆,
@DatabaseField(columnName = "city_id",generatedId = true,useGetSet = true)
private Integer cityId;
@DatabaseField(columnName = "city_name",useGetSet = true)
private String cityName;
@ForeignCollectionField
private ForeignCollection<Client> clientList;
这些 bean 只是一个示例,但比方说,我想在删除城市时删除所有具有外国城市 cityId 的客户端。
请问这怎么可能?
ORMLite http://ormlite.com/不支持级联删除@Majid。目前这超出了它所认为的“精简”范围。如果您删除city
那么你需要删除clients
用手。
确保这一点的一种方法是CityDao
覆盖的类delete()
方法并通过发出删除ClientDao
同时。就像是:
public class CityDao extends BaseDaoImpl<City, Integer> {
private ClientDao clientDao;
public CityDao(ConnectionSource cs, ClientDao clientDao) {
super(cs, City.class);
this.clientDao = clientDao;
}
...
@Override
public int delete(City city) {
// first delete the clients that match the city's id
DeleteBuilder db = clientDao.deleteBuilder();
db.where().eq("city_id", city.getId());
clientDao.delete(db.prepare());
// then call the super to delete the city
return super.delete(city);
}
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)