玩框架Ebean的两个ManyToMany关系返回相同的数据 [英] Play Framework Ebean two ManyToMany relations return same data

查看:88
本文介绍了玩框架Ebean的两个ManyToMany关系返回相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

@Entity
public class Document extends Model
{
    @Id
    private Long id;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "developers")
    private Set<Tester> developers = new HashSet<>();

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "testers")
    private Set<Tester> testers = new HashSet<>();
}

我正在使用JoinTable批注,否则对于多对多关系,我最终得到相同的联接表.效果很好,我生成了两个表(开发人员和测试人员).

I am using the JoinTable annotation otherwise I end up with the same join table for the many-to-many relation. This works well and I get two tables generated (developers and testers).

我什至能够正确保存数据.设置开发人员和/或测试人员,然后保存文档实体可以正常工作.

I am even able to save the data properly. Setting the developers and/or testers and then saving the document entity works properly.

现在的问题是当我做类似的事情时

Now the problem is that the moment I do something like:

Document.find.all()以获取可用的文档,尽管数据库中的数据不同,但是开发人员和测试人员字段返回的数据相同.进行document.getDevelopers()document.getTesters()会返回相同的数据,而getDevelopers()总是隐藏 getTesters()数据.

Document.find.all() to get the available Documents, the developers and the testers fields return the same data, despite the data being different in the database. Doing document.getDevelopers() and document.getTesters() return the same data with getDevelopers() always hiding the getTesters() data.

这是Ebean ORM中的一些错误/限制吗?

Is this some bug/limitation in the Ebean ORM?

我正在使用Play 2.3.8

I am using Play 2.3.8

推荐答案

明确获取字段将返回正确的数据.

Explicitly fetching the fields returns the proper data.

只需定义自己的find方法,如下所示:

Just define own find method like this:

public static List<Document> findAll() {
    return Ebean.find(Document.class)
                .fetch("developers")
                .fetch("testers")
        .findList();
}

仍然想知道是否还有更好的方法...

Still wondering if there are better ways...

这篇关于玩框架Ebean的两个ManyToMany关系返回相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆