开发者

Relations in Spring Web MVC (Using Roo)

What is the correct way to specify a one-to-many relationship in Spring Web MVC (using Spring Roo)?

Example: A P开发者_JAVA百科erson has a name and an email. A Team has a name. A Person has a membership in a Team, and a Team has zero or more members. The user would like to a) Set the membership for a person, b) Set the members for a Team.

If the relation is created using a reference field for Person, members are not visible in the view for Team. There's a similar result if the relation is created using a set field for Team (which really is a many-to-many relation anyway).

What am I missing?


What you need here is a bidirectional relationship (which is not created by default).

When you generate your entities, you need to add both the Set association in Team, AND the Person association in Team. It will probably also be a good idea (depending on your naming convention to add the mappedBy attribute in the OneToMany annotation on the generated Team Set. If you want to get this done by Roo, just used --mappedBy on the field set command. The value for this will be the field name of the Team reference in the Person entity.

With both references in place, roo should generate the correct scaffolding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜