<div dir="ltr">&gt;&gt;     * JSF : getAll<br>&gt;&gt;     * REST : listAll<br><br>&gt; They do look similar, but they&#39;re not the same in all respects.<br>&gt; The one in REST will contain JOIN FETCH expressions when relationships (@OneToMany, @ManyToMany etc.) are found in the class.<br>
&gt; This was done to ensure that serialization would not emit incomplete object graphs.<br><div class="gmail_extra"><br></div><div class="gmail_extra">When you have too many @OneToMany or @ManyToMany relationships, you end up with several queries that JOIN FETCH several/different relationships. So what I usually do when things are complex is :</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">findAll</div><div class="gmail_extra">findAllWithRelations (meaning all relations are FETCH)</div><div class="gmail_extra"><br></div><div class="gmail_extra">or more specific (when things are really really complex)</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">findAllWithBooks</div><div class="gmail_extra">findAllWithAuthors</div><div class="gmail_extra">findAllWithBooksAndAuthors</div><div class="gmail_extra"><br></div>
<div class="gmail_extra">Antonio<br><br><div class="gmail_quote">2013/10/21 Vineet Reynolds Pereira <span dir="ltr">&lt;<a href="mailto:vpereira@redhat.com" target="_blank">vpereira@redhat.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Antonio Goncalves&quot; &lt;<a href="mailto:antonio.mailing@gmail.com">antonio.mailing@gmail.com</a>&gt;<br>
&gt; To: &quot;forge-dev List&quot; &lt;<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
&gt; Sent: Sunday, October 20, 2013 10:20:49 PM<br>
&gt; Subject: [forge-dev]  Wondering about coding convention #philosophy<br>
&gt;<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I love Forge because it generates code. And that&#39;s why my customers start to<br>
&gt; love it too. Basically, they look at Forge as the &quot;way to write Java EE<br>
&gt; code&quot; or if you like &quot;if those guys write code like this, then we should&quot;.<br>
&gt;<br>
&gt; I am digging into some details of the generated code (I am writing a blog<br>
&gt; about several architectural styles starting with Forge) and I feel coding<br>
</div>&gt; convention should be homogenized . I know extensions are written by<br>
<div class="im">&gt; different individuals, but some basic coding conventions should be applied.<br>
<br>
</div>+1.<br>
<br>
I would consider these architectural styles more than coding conventions,<br>
and I believe it would be wise to &#39;standardize&#39; some of these for Java EE 6+.<br>
<div class="im"><br>
&gt; For example, when you generate a web app with REST and Faces scaffolding,<br>
&gt; you get some difference :<br>
&gt;<br>
&gt;<br>
</div>&gt;     * Faces Backing Bean use query builder (e.g getAll method is<br>
&gt;     entityManager.createQuery(criteria.select(criteria.from(Book.class))).getResultList();<br>
&gt;     and<br>
&gt;     * REST Endpoint use dynamic queries (the list all method is &quot;SELECT<br>
<div class="im">&gt;     DISTINCT b FROM Book b ORDER BY <a href="http://b.id" target="_blank">b.id</a> &quot;))<br>
&gt; Method names are different and do the same :<br>
&gt;<br>
&gt;<br>
</div>&gt;     * JSF : getAll<br>
&gt;     * REST : listAll<br>
<br>
They do look similar, but they&#39;re not the same in all respects.<br>
The one in REST will contain JOIN FETCH expressions when relationships (@OneToMany, @ManyToMany etc.) are found in the class.<br>
This was done to ensure that serialization would not emit incomplete object graphs.<br>
There are various factors that would be at work here in determining what JPQL queries should be generated.<br>
Obviously in this context, exposing JPA entities directly is bad idea and projections/views of the entities should be used instead.<br>
<br>
IMHO we should not be putting persistence concerns in either the JSF beans or the REST resources.<br>
They should go into a service or a repository or whatever data access pattern is suitable for the context.<br>
This is where we lack any standardization at the moment, and it would be better to not limit this exercise to improving the conventions alone, but also the architecture.<br>
<br>
I don&#39;t believe in packing in persistence concerns however small, into these beans for<br>
 * we run the risk of generating God classes, and<br>
 * we&#39;d leave users with the task of creating/extracting the persistence layer (which should have been done by Forge in the first place).<br>
<br>
&gt;<br>
&gt; Attributes<br>
&gt;<br>
&gt;<br>
&gt;     * private EntityManager em;<br>
&gt;     * private EntityManager entityManager; // em would be better<br>
<div class="im">&gt; Or the use of this keyword (JSF beans use this.entityManager instead of<br>
&gt; directly em in REST)<br>
&gt;<br>
&gt; And there are several examples like this. If Forge is seen as &quot;the way of<br>
&gt; writing code&quot; maybe something should be created to get homogenized code.<br>
&gt; PMD, Checkstyle, human review and so one.....<br>
&gt;<br>
&gt; Just wondering....<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Antonio Goncalves<br>
&gt; Software architect and Java Champion<br>
&gt;<br>
&gt; Web site | Twitter | LinkedIn | Paris JUG | Devoxx France<br>
&gt;<br>
</div><div class=""><div class="h5">&gt; _______________________________________________<br>
&gt; forge-dev mailing list<br>
&gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
_______________________________________________<br>
forge-dev mailing list<br>
<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Antonio Goncalves <br>Software architect and Java Champion<br><br><a href="http://www.antoniogoncalves.org/" target="_blank">Web site</a> | <a href="http://twitter.com/agoncal" target="_blank">Twitter</a> | <a href="http://www.linkedin.com/in/agoncal" target="_blank">LinkedIn</a> | <a href="http://www.parisjug.org/" target="_blank">Paris JUG</a> | <a href="http://www.devoxx.fr/" target="_blank">Devoxx France</a>
</div></div>