Google Cloud Endpoints,Objectify和Persistence

时间:2021-01-17 23:12:50

I've follow this tuto for my project (https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial), and everything works fine.

我已经按照这个tuto进行了我的项目(https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial),一切正常。

But when I wanted to use with objectify classes for my entities, It doesn't work, i can't retrieve data on my datastore with my android app !

但是,当我想使用objectify类为我的实体,它不起作用,我无法使用我的Android应用程序检索我的数据存储区中的数据!

For example, with that code it's okay, I can get my user back from my android app:

例如,使用该代码,没关系,我可以从我的Android应用程序中恢复用户:

import javax.jdo.annotations.Index;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@Index
public class Utilisateur {

    //Nos variables de classes
    @Id String num_portable; //Clé pour notre entité NOTION CLE PRIMAIRE String car c'est à nous de le définir.
    Boolean sexe;
    int date_naissance;
    String position_geo;
    String liste_contact;
    Boolean blacklistage;

    //Constructeur par défaut (Obligatoire pour Objectify)
    private Utilisateur(){}

    public Utilisateur (String num_portable, Boolean sexe, int date_naissance, String position_geo, String liste_contact, Boolean blacklistage) {

        this.num_portable=num_portable;
        this.sexe=sexe;
        this.date_naissance=date_naissance;
        this.position_geo=position_geo;
        this.liste_contact=liste_contact;
        this.blacklistage=blacklistage;                
    }

    public String getNum_portable() {
        return num_portable;
    }



}

But I don't use Objectify.. When I want to use Objectify, with that code, it doesn't works : I'm just replace this code :

但我不使用Objectify ..当我想使用Objectify时,使用该代码,它不起作用:我只是替换这段代码:

import javax.jdo.annotations.Index;
import javax.persistence.Entity;
import javax.persistence.Id;

With this one :

有了这个:

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;

and I get this error on my app engine:

我在我的应用引擎上收到此错误:

com.google.api.server.spi.SystemService invokeServiceMethod: Class Utilisateur for query has not been resolved. Check the query and any imports/aliases specification
javax.persistence.PersistenceException: Class Utilisateur for query has not been resolved. Check the query and any imports/aliases specification

So my question is: Can we use Objectify with Android App or the data persistence doesnt work with it (And App Engine)?

所以我的问题是:我们可以将Objectify与Android App一起使用,还是数据持久性不能与它一起使用(和App Engine)?

Edit: That is my code on my android app that call backend(Same code as here => https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial):

编辑:这是我的Android应用程序上调用后端的代码(与此处相同的代码=> https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-后端教程):

public class JeveuxvoirActivity extends Activity {


      private ListView utilisateursList;
      private List<Utilisateur> utilisateurs = null;

    //Création de notre activité
      public void onCreate(Bundle savedInstanceState) {

            //Création de notre interface graphique
            super.onCreate(savedInstanceState);

            //Remove title bar
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);
            //On définit le Layout de notre activité
            setContentView(R.layout.activity_jeveuxvoir);

            utilisateursList = (ListView) findViewById(R.id.list_principal_user);

            // start retrieving the list of nearby places
            new ListOfUtilisateursAsyncRetriever().execute();



        }    


        //*******************************************************
        //                  FONCTIONS ASYNC
        //*******************************************************
      /**
       * AsyncTask for retrieving the list of places (e.g., stores) and updating the
       * corresponding results list.
       */
      private class ListOfUtilisateursAsyncRetriever extends AsyncTask<Void, Void, CollectionResponseUtilisateur> {

        @Override
        protected CollectionResponseUtilisateur doInBackground(Void... params) {


          Utilisateurendpoint.Builder endpointBuilder = new Utilisateurendpoint.Builder(
              AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);

          endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);


          CollectionResponseUtilisateur result;

          Utilisateurendpoint endpoint = endpointBuilder.build();

          try {
            result = endpoint.listUtilisateur().execute();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            result = null;
          }
          return result;
        }

        @Override
        @SuppressWarnings("null")
        protected void onPostExecute(CollectionResponseUtilisateur result) {
          ListAdapter utilisateursListAdapter = createUtilisateurListAdapter(result.getItems());
          utilisateursList.setAdapter(utilisateursListAdapter);

          utilisateurs = result.getItems();
        }
      }

        private ListAdapter createUtilisateurListAdapter(List<Utilisateur> utilisateurs) {

            List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
            for (Utilisateur utilisateur : utilisateurs) {
              Map<String, Object> map = new HashMap<String, Object>();
              map.put("utilisateurIcon", R.drawable.ic_launcher);
              map.put("utilisateurPort", utilisateur.getNumPortable());
              data.add(map);
            }

            SimpleAdapter adapter = new SimpleAdapter(JeveuxvoirActivity.this, data, R.layout.utilisateur_item,
                new String[] {"utilisateurIcon", "utilisateurPort"},
                new int[] {R.id.utilisateur_Icon, R.id.utilisateur_port});

            return adapter;
          }

1 个解决方案

#1


1  

JPA and objectify are 2 alternatives for connecting to dataStore. Avoid using both together. Both have their own conventions that work best if used alone.

JPA和objectify是连接到dataStore的两种选择。避免一起使用。如果单独使用,两者都有自己的约定。

#1


1  

JPA and objectify are 2 alternatives for connecting to dataStore. Avoid using both together. Both have their own conventions that work best if used alone.

JPA和objectify是连接到dataStore的两种选择。避免一起使用。如果单独使用,两者都有自己的约定。