简体   繁体   English

与JDO和GAE的多对一关系

[英]Many-to-One relationship with JDO and GAE

I have searched all over the site But there even not one example of how to make with jdo a many to one relation ship. 我搜遍了整个网站但是,甚至没有一个如何用jdo制作多对一关系的例子。 https://developers.google.com/appengine/docs/java/datastore/jdo/relationships https://developers.google.com/appengine/docs/java/datastore/jdo/relationships

but I couldn't find out how to do it. 但我无法找到如何做到这一点。

lets say I have this DB: 让我说我有这个DB:

Cars(CarID,OwnerID,...)
Owner(OwnerID,...)

And I want to create new entity for a new car - how can i make it? 我想为新车创造新的实体 - 我怎样才能做到?

I dont want to make another entity for an owner if the owner is already on the db but if he is not I like to make new owner. 如果所有者已经在数据库中,我不想为所有者创建另一个实体,但如果他不是我想建立新的所有者。

Thanks for any example code or blog link on how to deal with it. 感谢您提供有关如何处理它的任何示例代码或博客链接。

EDIT: Its seems like you think its bidir relationship. 编辑:它似乎你认为它的双向关系。 So i think you didnt understand me well. 所以我觉得你不太了解我。 lets say we are not talking about Car and Owner we are talking now on Genre and Song 让我们说我们不是在谈论汽车和所有者我们正在谈论的流派和歌曲

Genre-dont need to know about Song! 类型 - 不需要了解宋! Song need to know his Genre! 宋需要知道他的类型!

my classes are: 我的课程是:

public class Genre {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
long id;
@Persistent
String genre;

} AND: } AND:

public class Song{
long id;
    @Join(name="GENRE_JOIN")
Genre genre;

} }

thanks in advance! 提前致谢!

All of the GAE docs say refer to the DataNucleus JDO docs for full details, so I don't see why they should provide examples of everything. 所有GAE文档都说参考DataNucleus JDO文档以获取完整的详细信息,因此我不明白为什么他们应该提供所有内容的示例。 Since your relation is seemingly (not that you define it) a 1-N BIDIR relation at Owner side, and N-1 BIDIR at Car side then http://www.datanucleus.org/products/accessplatform_3_1/jdo/orm/many_to_one.html The JDO spec would also have ample examples. 由于您的关系似乎 (不是您定义)在所有者方面的1-N BIDIR关系,以及在Car侧的N-1 BIDIR关系,然后http://www.datanucleus.org/products/accessplatform_3_1/jdo/orm/many_to_one .html JDO规范也有很多例子。

class Owner {
    @Persistent(mappedBy = "owner")
    private List<Car> cars;
}

class Car {
    @Persistent
    private Owner owner;
}

Car car = new Car();
//search for the owner.
car.setOwner(owner);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM