Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android云端点:实体键作为其他实体的数据值_Android_Google App Engine_Jpa_Google Cloud Endpoints - Fatal编程技术网

Android云端点:实体键作为其他实体的数据值

Android云端点:实体键作为其他实体的数据值,android,google-app-engine,jpa,google-cloud-endpoints,Android,Google App Engine,Jpa,Google Cloud Endpoints,我有一个appenginejava项目,它的实体是 @Entity public class UserDB { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Key key; private String firstName; private String lastName; private String userName; } @Entity public c

我有一个appenginejava项目,它的实体是

@Entity
public class UserDB {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    private String firstName;
    private String lastName;
    private String userName;
}

@Entity
public class HistoryDB {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    @ManyToOne
    private Key userId; //Key from the UserDB

    public Key getKey() {
        return key;
    }
    public void setKey(Key key) {
        this.key = key;
    }
    public Key getUserId() {
        return userId;
    }
    public void setUserId(Key userId) {
        this.userId = userId;
    }
}
eclipse为Android端生成的客户端端点库为每个实体生成多个Key.java文件,因此很难使用上述方案,因为UserDB的密钥不能用作HistoryDB中userID密钥的参数

我如何处理这个问题


在另一个数据库中使用HistoryDB中的键作为数据值时,我也遇到了类似的情况。在UserDB中,我可以选择使用用户名作为HistoryDB中的唯一键,但如何在其他数据库中获得HistoryDB的唯一键?

如果您有一个不传递键对象的关系,则在HistoryDB中使用UserDB。除此之外,删除manytone注释拥有密钥的想法类似于传统的rdbms系统,该系统将密钥作为外来项来存储关系。例如,当我在HistoryDb中使用UserDb时,它如何在内部工作?还有,删除ManyToOne会有什么帮助?ManyToOne说这是一种JPA关系。有什么就没有什么。这是O-O世界,而不是RDBMS世界。去谷歌自己的测试,谢谢尼尔。因此,如果我理解正确,它将被更改为HistoryDb中的private UserDb UserDb,而不使用@manytone?在这种情况下使用@JoinColumnname=Key也会有价值吗?不会。如果你把一个真正的关系放在private UserDB UserDB那里,那么你需要多个关系,因为它是一个关系。如果你坚持这个关键的东西,那么你不能有很多