Play Framework joins and the model

末鹿安然 提交于 2019-12-12 00:44:37

问题


This isn't a problem, its more of a "is this the right approach" kind of deal.

So lets say I have a model like this

class A extends Model{
    @OneToMany(cascade = CascadeType.ALL)
    public B;
}

class B extends Model{

   String c;
}

Now I want to access all objects of A that have a particular value of c in their B objects.

So should I:

  1. Get all objects of B with a certain value c and then find corresponding A's with those objects(if so how, getting confused)
  2. Get all objects of A with find.all() then look through the list (seems a bad idea as there will be a large amount of A's and not so many B's).

Any help would be appreciated (oh and assume I've written @Entity and @Required and all the rest appropriately)


回答1:


Option 1 is the right way to go. You can use a query such as

A.find().where().eq("b.id", yourBId).findList();

Possibly adding a fetch("b"), if it isn't fetched automatically.



来源:https://stackoverflow.com/questions/17449406/play-framework-joins-and-the-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!