GAE+Objectify - Parameterized type com.googlecode.objectify.Ref not supported

后端 未结 2 1142
轻奢々
轻奢々 2020-12-20 03:33

I am using Google App engine1.9.3, Eclipse, Objectify5.03. My Class is as follows:

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annot         


        
2条回答
  •  抹茶落季
    2020-12-20 04:03

    ApiResourceProperty annotation does not work for Google Emdpoints+Objectify combinations as Ref or Key is Objectify specific class and Google Endpoints does not recognize them and will give a error when you try to generate the Client Libraries. I changed the User class as below.

     @Id private Long userId;
     @Index private String userName;
     @Load private UserDetails userDetails;
     @Load private UserPassword userPassword;
     @Load private ArrayList userAccounts;
    
     //getters and setters
    

    When I retrieve the user by user name as below, I get the User, UserDetails, UserPassword and also the list of User accounts thru the getters (in one shot)

    @ApiMethod(name = "getUserByName", path = "get_user_by_name")
    public User getUserByName(@Named("userName") String userName) {
    
        User user = null;
        try {
             user = ofy().load().type(User.class).filter("userName", userName).first().now();
             if(user != null)
                 log.info("UserEndpoint.getUserByName...user retrieved="+user.getUserId());
             else
                 log.info("UserEndpoint.getUserByName...user is null");
        } catch(Exception e) {
            log.info("UserEndpoint.getUserByName...exception="+e.getMessage());
        }
        return user;
    }
    

    When I use the Datastore Viewer on Google Console to view the data, I see some entries in the userDetails, userPassword and Accounts columns in the User table. I assume that these are references to the actual data in their respective tables and not a copy of the data itself. Hope this helps.

提交回复
热议问题