爲了簡化,我省略了一些代碼(包聲明,導入,其他字段) 。 我這裏有簡單的一對多關係。 它工作得很好,直到這一刻。一對多關係。從數據存儲中選擇對象
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable="true")
class Restaurant implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key id
@Persistent(mappedBy = "restaurant")
List<RestaurantAddress> addresses = new ArrayList<RestaurantAddress>()
}
// - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable="true")
class RestaurantAddress implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key id
@Persistent
Restaurant restaurant
}
現在我需要獲得(選擇)從數據庫中的所有的餐館:
def getRestaurantsToExport(final String dst, final int count) {
String field = restaurantExportFields[dst]
return transactionExecute() { PersistenceManager pm ->
Query q = pm.newQuery(Restaurant.class)
q.filter = "$field == null"
q.setRange(0, count)
return q.execute()
}
}
但也有問題 - 查詢給我12家餐館(如數據庫),但 每家餐廳都有0地址,但在數據存儲每家餐館都有 最低2添加resses。
有沒有人有同樣的問題或知道解決方案?
您是否有鏈接到與谷歌相關的此討論? – pkaeding 2010-10-01 21:25:30