Results 1 to 5 of 5

Thread: (MVC) Views and lists

  1. #1

    Default (MVC) Views and lists

    I have A with a @OneToMany to B (and B with a @ManyToOne back to A).

    But when I view A's:
    * show.jspx, I see no references to B whatsoever: see other, ad hoc thread and Jira ticket.
    * update.jspx, I only see the message "This relationship is managed from the <B> side." instead of a list of my Bs.
    Is this the current implementation, or is there something wrong with my design (for example the cardinalities).

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    To create a bi-directional relationship from a JPA perspective you also need to make sure to include the mappedBy attribute. Otherwise Roo would scaffold your forms in a way that the relationship is managed from the many side. There is an example at the end of this chapter in our docs: http://static.springsource.org/sprin...html#jsp-views

    Also, the clinic.roo script illustrates this style of relationship as well.
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #3

    Default

    Stefan,

    I am aware of the mappedBy attribute, and use it.

    In the project that I attached to
    take for example:
    *** "Project" for A, and
    *** "RiskIndex" for B.

  4. #4

    Default

    While writing unit tests for some manual methods, I realize another possible issue.

    Using the MVC UI, I associate Projects and RiskIndexes on the RiskIndex UI, given that it manages the relationship.

    If I do the same via API, i.e.:
    riskIndex1.setProject(project);
    riskIndex3.setProject(project);
    riskIndex4.setProject(project);
    then look at project.getRiskIndexes(), it is empty. Which is understandable given the "simple" setters currently generated.

    But given the bi-directional relationship, should the setter be generated as follows:

    public void RiskIndex.setProject(Project project) {
    this.project = project;
    project.getRiskIndexes().add(this);
    }
    Yes we can override / push-in the setters manually, but if they can be generated the right way automatically...

  5. #5

    Default

    Well, my latest "issue" may be that:
    * In my unit tests I am not persisting anything, and
    * The correct management of bi-directional relationships relies on the FKs and JPA...

    Because when I reproduce my unit tests on the MVC UI I get the expected results, even though I (can) only build collections via the "many" side.

    The lists are still not displayed correctly however, so my initial issue remains...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •