简体   繁体   English

将logisimayml模块与Play框架一起使用

[英]Using logisimayml module with the Play Framework

I am using the logisimayml 1.5 module with my Play app to produce yml from the contents in my live database. 我在我的Play应用程序中使用logisimayml 1.5模块,以从实时数据库中的内容生成yml。 The module traverses the JPA classes to identify children to determine what gets written out into the yml. 该模块遍历JPA类以标识子级,以确定将哪些内容写出到yml中。

So if I had two simple JPA classes like this: 因此,如果我有两个简单的JPA类,例如:

public class Parent extends Model {

    @OneToMany(mappedBy = "parent", targetEntity = Child.class)
    public List<Child> children;

    ...
}

public class Child extends Model {

    @ManyToOne
    @JoinColumn(name = "parent_id")
    public Parent parent;

    ...
}

When I run logisimayml, it will produce a data.yml file that looks like this: 当我运行logisimayml时,它将生成一个data.yml文件,如下所示:

Parent(Parent_1):
 name: Bill
 children:
 - Child_1

Parent(Parent_2):
 name: Bill

Child(Child_3):
 name: Jill

Child(Child_1):
 name: Jill
 parent: Parent_1

Now the yml above does represent what the JPA classes represent however I would like to use the data.yml file for loading into my app using: 现在,上面的yml确实代表了JPA类所代表的内容,但是我想使用data.yml文件通过以下方式将其加载到我的应用程序中:

Fixtures.loadModels("data.yml");

This doesn't quite work because Bill is first and it wants to find the child Jill. 这不是很有效,因为Bill是第一位,并且它想找到孩子Jill。 Jill however has not yet been declared and therefore it falls over. 但是,Jill尚未被宣布,因此失败了。 This stems from the fact that I have used both @OneToMany in Parent and @ManyToOne in Child meaning it is bi-directional. 这源于以下事实:我在Parent中使用了@OneToMany,在Child中使用了@ManyToOne,这意味着它是双向的。 I could remove the @OneToMany but I still want it in there for my code. 我可以删除@OneToMany,但是我仍然希望在其中添加代码。 Does anyone know what I could do to keep the JPA classes as they are but have the yml render without an infinite loop between the Parent and Child? 有谁知道我该怎么做才能保留JPA类,但是让yml呈现器在Parent和Child之间没有无限循环?

Update: Here the exception I see when I start up my Play app pointing to the data.yml created by logisimayml: 更新:这是我启动Play应用程序时看到的异常,该异常指向由logisimayml创建的data.yml:

RuntimeException occured : Cannot load fixture data.yml: No previous reference found for object of type sites with key User_25

The first object in the data.yml references User_25 as a child. data.yml中的第一个对象将User_25引用为子对象。 The declaration of User_25 is much further down in my data.yml. User_25的声明在我的data.yml中更远。 As Luffy mentioned below, my simple Parent-Child example does not actually cause the exception to occur. 如下面的路飞所述,我简单的“父子”示例实际上并未导致异常的发生。 My actual project has quite a large database so it is hard to replicate in a simple example here, though I thought it had something to do with the bi-directional annotations but I guess not after all. 我的实际项目有一个很大的数据库,因此很难在这里的一个简单示例中进行复制,尽管我认为它与双向注释有关,但我想毕竟不是。 I also updated the data.yml for my example above. 我还在上面的示例中更新了data.yml。 I actually do what Luffy did and created an actual project with the simple Parent-Child example and after running the module, it actually produced something slightly different than my hand crafted yml. 我实际上做了Luffy的工作,并使用简单的Parent-Child示例创建了一个实际项目,并且在运行该模块之后,它实际上产生的东西与我手工制作的yml略有不同。 Using that yml in the Fixtures.loadModels(..) call actually works though so it doesn't really reflect the issue exactly as I see it in production so I will have to get back to you on that. 尽管在Fixtures.loadModels(..)调用中使用该yml实际上可以正常工作,所以它并不能真正反映出我在生产中看到的问题,因此我将不得不与您联系。

Try to use "fetch = FetchType.LAZY" in ManyToOne annotation. 尝试在ManyToOne批注中使用“ fetch = FetchType.LAZY”。 This may help to fix your issue. 这可能有助于解决您的问题。

@ManyToOne(name = "parent_id", fetch = FetchType.LAZY)

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

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