Domanda

ho omesso qualche codice (dichiarazioni del pacchetto, le importazioni, gli altri campi) per brevità. Ho qui semplice relazione uno-a-molti. Ha funzionato bene fino a questo momento.

@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
}

Ora ho bisogno di ottenere (seleziona) tutti i ristoranti da DB:

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()
   }
 }

Ma ci sono problemi - interrogazione mi dà 12 ristoranti (come nel DB), ma Ogni ristorante ha 0 Indirizzo ma in ogni ristorante ha Datastore minimo 2 indirizzi.

Avere qualcuno lo stesso problema o conosce la soluzione?

È stato utile?

Soluzione 2

Se qualcuno avrà lo stesso problema:

Sostituire

@Persistent(mappedBy = "restaurant")
 List<RestaurantAddress> addresses = new
ArrayList<RestaurantAddress>

@Persistent(mappedBy = "restaurant",defaultFetchGroup = "true")
 List<RestaurantAddress> addresses = new
ArrayList<RestaurantAddress>

Un altro metodo è che si deve "toccare" si rivolge immobili per Ogni ristorante nella lista recuperato prima della chiusura PersistentManager. Dopo PersistenManager voi di essere chiuso non si può recuperare qualsiasi cosa, da datastore e ristorante mantiene nullo.

soluzione trovata con l'aiuto di google-AppEngine-java utenti.

Altri suggerimenti

sei sicuro gli indirizzi non sono caricato in modo pigro? Solo una supposizione ... c'è qualche modo per forzare una loading "ansioso" degli oggetti

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top