我正在尝试使用 Spring Roo 生成具有 @OneToMany
单向关系的实体。这是我尝试过的:
entity --class ~.family.Child
field string --fieldName name
controller scaffold ~.web.ChildController
entity --class ~.family.Father
field string --fieldName name
field set --fieldName children --element ~.family.Child --cardinality ONE_TO_MANY
controller scaffold ~.web.FatherController
perform package
这会生成预期的实体和数据库表(包括链接表)。Father
实体是使用以下符合 JPA 规范的注释生成的:
@OneToMany(cascade = CascadeType.ALL)
private Set<family.Child> message = new java.util.HashSet<family.Child>();
但是当我转到 Roo 生成的管理页面并单击 Create Father
时,我发现以下消息:
创建父亲
Name: (field to enter name)
Children: This relationship is managed from the Father side.
这看起来像是 Roo 中的错误。有没有人找到解决方法?还是我这里有错误?
最佳答案
好的,这里有一个解决方法:在 fathers/create.jspx
文件中,Roo 生成以下行:
<field:simple field="children" id="c:family.Father.children" messageCode="entity.reference.not.managed"
messageCodeAttribute="Child" z="dMKrUOiCeYNub4vNayuiWJ99s1k="/>
这应该被替换为:
<field:select field="children" id="c:family.Father.children" itemValue="id"
items="${children}" multiple="true" path="/children"/>
它应该可以工作。
关于java - Spring Roo 的@OneToMany 注释问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3196666/