Note that there are some explanatory texts on larger screens.

plurals
  1. POGroup by in JPA
    primarykey
    data
    text
    <p>My Question is why the <code>GROUP BY</code> didn't show in the glassfish logs. i added the following data below because someone wants to see it </p> <pre><code> public List&lt;Message&gt; listAllMessageBySender(String currentUserID) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenceUnit"); EntityManager entityManager = emf.createEntityManager(); TypedQuery&lt;Message&gt; eq = entityManager.createQuery("SELECT m FROM Message m WHERE m.sendBy.userId = :userid GROUP BY m.sendTo.userId", Message.class); eq.setParameter("userid", Integer.parseInt(currentUserID)); List&lt;Message&gt; message = eq.getResultList(); return message; } </code></pre> <p>Glassfish 3.1.2.Logs</p> <pre><code>FINE: SELECT id, message, send_date, send_by, send_to FROM message WHERE (send_by = ?) bind =&gt; [50] Data: User A : sendBy.userId = 50 User B : sendTo.userId = 44 User C : sendTo.userId = 43 id send_date send_by send_to message 1 2013-03-14 14:58:46 44 50 50 send message to 44 2 2013-03-14 14:58:46 50 44 reply from 44 to 50 3 2013-03-14 17:38:52 44 50 2nd reply to 50 6 2013-03-14 18:22:10 50 44 44 reply to 50 7 2013-03-14 18:22:10 50 43 new in the query above is i want to list all the user sent from User A. it causes duplication because there is two send_to 44. the xhtml below shows : &lt;ui:repeat value="#{messageController.items}" var="messageItem"&gt; &lt;br /&gt; &lt;div onclick="loadMessage()"&gt; &lt;h:panelGroup layout="block" &gt; &lt;p:graphicImage height="50" width="50" value="#{messageItem.sendTo.profilePicture}"/&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup layout="block" style="width: 270px;"&gt; &lt;h:outputText value="#{messageItem.sendTo.registerName}"/&gt; &lt;h:panelGroup layout="block" style="float:right;"&gt; &lt;h:outputText value="#{messageItem.sendDate}" &gt; &lt;f:convertDateTime pattern="HH:mm"/&gt; &lt;/h:outputText&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; &lt;/div&gt; &lt;p:remoteCommand name="loadMessageBean" action="#{messageController.loadMessage(messageItem.id)}" /&gt; &lt;/ui:repeat&gt; ERD User Table Message Table user_id message_id register_name send_date send_to ----&gt; referenced by user_id User Table send_by ----&gt; referenced by user_id User Table </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload