<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    I find it very nice ! However, as max pointed out, there are some
    issues when generating the entities from the DB. <br>
    <br>
    And it seems pretty simple to implement it as well. We could add
    another option to the entity plugin to allow the user to choose if
    that piece of code should be generated. Is there already a JIRA
    issue for this ?<br>
    <br>
    Best Regards,<br>
    <br>
    George Gastaldi<br>
    <br>
    On 09/24/2012 11:37 AM, Marius Bogoevici wrote:
    <blockquote
      cite="mid:C4B6EF70-C3F7-41DC-9F6D-CBF2B86E107B@redhat.com"
      type="cite">
      <pre wrap="">All,

I have a proposal for the persistence plugin, regarding the handling of inverse relationships.

When working with inverse relationships in Hibernate and JPA, it is a common and encouraged practice to include convenience methods for correctly managing the inverse end of the relationship, so that the entity user would be relieved from the burden of setting each end manually when the relationship. e.g. 'addSubCategory' in

@Entity
public class SubCategory {

 @ManyToOne
private Category parent;
}


@Entity
public class Category {

  @OneToMany(mappedBy = "parent")
  private Set&lt;SubCategory&gt; subcategories = new HashSet&lt;SubCategory&gt;();

  ….


  public void addSubCategory(SubCategory subcategory) {
        this.subcategories.add(subcategory);
        subcategory.setParent(this);
  }

}

or something more elaborate (null checks etc) but to the effect of . This can be combined with returning non-modifiable collections by the getters, etc. but the gist of it is to provide a single operation through which developers will set up the bi-directional relationship, thus preventing the model from becoming inconsistent (or even not persisted correction).

Essentially this is a quite established good practice, which the ones of us who admit to being old enough to have read Gavin&amp;Christian's book will remember. Now this is a PITA to do manually, but Forge could easily take care of it.

Lincoln and I have discussed this on IRC, and whiles this has been deemed a good idea,  we're wondering what everyone else thinks. So, thoughts?

Cheers,
Marius


_______________________________________________
forge-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/forge-dev">https://lists.jboss.org/mailman/listinfo/forge-dev</a>
</pre>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <b>George Gastaldi</b> | <i>Senior Software Engineer</i> <br>
      JBoss Forge Team<br>
      Red Hat<br>
    </div>
  </body>
</html>