Eclipse GAE+;Objectify-不支持参数化类型com.googlecode.Objectify.Ref

Eclipse GAE+;Objectify-不支持参数化类型com.googlecode.Objectify.Ref,eclipse,google-app-engine,google-cloud-endpoints,objectify,Eclipse,Google App Engine,Google Cloud Endpoints,Objectify,我正在使用谷歌应用程序engine1.9.3,Eclipse,Objectify5.03。我的班级如下: import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Load; @Entity publ

我正在使用谷歌应用程序engine1.9.3,Eclipse,Objectify5.03。我的班级如下:

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;

@Entity
public class User {

@Id private Long userId;
private String userName;
@Load private Ref<UserDetails> userDetails;
@Load private Ref<UserPassword> userPassword;

//getters & setters 

}
import com.googlecode.objectify.Ref;
导入com.googlecode.objectify.annotation.Entity;
导入com.googlecode.objectify.annotation.Id;
导入com.googlecode.objectify.annotation.Load;
@实体
公共类用户{
@Id私有长用户Id;
私有字符串用户名;
@加载私有引用用户详细信息;
@加载私有Ref用户密码;
//接球手和接球手
}
当我尝试通过Eclipse为此类创建google端点时,出现以下错误: java.lang.IllegalArgumentException:不支持参数化类型com.googlecode.objectify.Ref

这是我第一次尝试客观化


知道我做错了什么吗。无论我读到什么,GAE endpoints和Objectify都应该有效,对吗?

Google Cloud endpoints无法序列化
Ref
对象,因为它是由
Objectify
定义的任意对象,因此不受错误指示的支持

这是云端点的已知限制,因为它不允许使用自定义对象。如果您感兴趣,这里有一个关于这一点的完整讨论线索:

您必须使用
@ApiResourceProperty
注释您的方法,并将其忽略属性设置为
true
,如下代码所示:

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;
import com.google.api.server.spi.config.AnnotationBoolean;
import com.google.api.server.spi.config.ApiResourceProperty;

@Entity
public class User 
{
    @Id private Long userId;
    private String userName;
    @Load private Ref<UserDetails> userDetails;
    @Load private Ref<UserPassword> userPassword;

    //getters & setters
    @ApiResourceProperty(ignored = AnnotationBoolean.TRUE) 
    public UserDetail getUserDetails(){
    }

    @ApiResourceProperty(ignored = AnnotationBoolean.TRUE) 
    public UserPassword getUserPassword(){
    }
}

但我认为更好的方法是重新考虑你的课程设计,或者重新思考您正在尝试的操作。

ApiResourceProperty注释不适用于Google Emdpoints+Objectify组合,因为Ref或Key是Objectify特定类,Google端点无法识别它们,并且在您尝试生成客户端库时会给出错误。我更改了用户类,如下所示

 @Id private Long userId;
 @Index private String userName;
 @Load private UserDetails userDetails;
 @Load private UserPassword userPassword;
 @Load private ArrayList<Account> userAccounts;

 //getters and setters

当我使用Google控制台上的Datastore Viewer查看数据时,我会在用户表的userDetails、userPassword和Accounts列中看到一些条目。我假设这些是对各自表中实际数据的引用,而不是数据本身的副本。希望这有帮助。

您可能应该在这个问题上添加与端点相关的标记,因为这是可以回答您问题的社区。我猜您的
User
类将有一个getter返回
UserDetails
UserPassword
对象,而不是它们各自的
Ref
s?如果是这样,您可能希望查看中的
@ApiResourceProperty
,因为您可能需要告诉云端点忽略您的私有Objectify
Ref
members.elcid,我知道这是一个简单的实现,我可以在同一个实体中拥有所有字段,但我试图找到Objectfy+Google端点是否能够支持一对一和一对多关系。例如,如果我的用户有一个帐户列表,我计划添加列表帐户。当我的前端从数据存储中检索用户时,帐户列表也应该对用户可用。我们的意思是,这种方式不可能,我需要在上添加一个单独的查询来获取用户的帐户。我向getter和setter添加了@ApiResourceProperty(ignored=AnnotationBoolean.TRUE),如上所述。但当我试图通过Eclipse为用户创建云端点类时,仍然会得到“由以下原因引起的:java.lang.IllegalArgumentException:参数化类型com.googlecode.objectify.Ref不受支持”。如果有人有任何其他建议,请让我知道。@DavidC据我所知,Google Cloud Endpoints(GCE)不知道如何序列化/反序列化objectify定义的自定义Ref对象,因此为什么编译失败,因为它不知道如何将您的帐户列表发送给您的客户。您可以尝试向客户端发送实际实体,而不是Ref。关于您最近的问题,请尝试使用@ApiResourceProperty(忽略=AnnotationBoolean.TRUE)注释Ref属性。您在这里所做的是创建嵌入实体的列表,而当您使用@Ref时,您与另一个实体有关系。。这就是为什么现在您可以在de DS viewer的1列中看到完整的对象。
 @Id private Long userId;
 @Index private String userName;
 @Load private UserDetails userDetails;
 @Load private UserPassword userPassword;
 @Load private ArrayList<Account> userAccounts;

 //getters and setters
@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;
}