title: Native query produces MySQL syntax error and unexpected result
body: <p>In my application, when a <code>User</code> removes a <code>Message</code>, I need to remove the relationship between the 2 entities while keeping them intact. Hence, I tried to delete rows directly from the relationship table using the following ways:</p>
  
  <p><strong>1.</strong></p>
  
  <pre><code>Query q = em.createNativeQuery("DELETE FROM User_Inbox WHERE User_USERNAME = :username AND Message_ID = :messageID");
  q.setParameter("username", username);
  q.setParameter("messageID", messageID);
  q.executeUpdate();
  </code></pre>
  
  <p><strong>2.</strong></p>
  
  <pre><code>Query q = em.createNativeQuery("DELETE FROM User_Inbox WHERE User_USERNAME = :username AND Message_ID = :messageID");
  q.setParameter("username", "'" + username + "'");
  q.setParameter("messageID", "'" + messageID + "'");
  q.executeUpdate();
  </code></pre>
  
  <p>The 1st and 2nd approaches produced the following exception:</p>
  
  <pre><code>Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
  You have an error in your SQL syntax; check the manual that corresponds to your 
  MySQL server version for the right syntax to use near ':username AND 
  Message_ID = :messageID' at line 1
  Error Code: 1064
  </code></pre>
  
  <p><strong>3.</strong></p>
  
  <pre><code>Query q = em.createNativeQuery("DELETE FROM User_Inbox WHERE User_USERNAME = ':username' AND Message_ID = ':messageID'");
  q.setParameter("username", username);
  q.setParameter("messageID", messageID);
  q.executeUpdate();
  </code></pre>
  
  <p>The 3rd approach did not produce any exceptions. It went through normally. However, nothing was deleted from the <code>User_Inbox</code> table.</p>
  
  <p><strong>4.</strong></p>
  
  <pre><code>Query q = em.createNativeQuery("DELETE FROM User_Inbox WHERE User_USERNAME = '" + username + "' AND Message_ID = '" + messageID + "'");
  q.executeUpdate();
  </code></pre>
  
  <p>The 4th approach worked perfectly. The query went through smoothly and a record was deleted properly.</p>
  
  <p>The last approach worked but the code doesn't look very neat to me. I'd be very grateful if someone could show me what I did wrong with the 1st three approaches.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Based on the <a href="https://stackoverflow.com/a/19254188/801434">answer</a> from D. Moore, I've just found out that named parameters cannot be used with native queries. This has been mentioned in this <a href="https://stackoverflow.com/questions/3144235/jpa-hibernate-native-queries-do-not-recognize-parameters">answer</a> by Pascal Thivent.</p>
  
  <blockquote>
    <p>Named parameters follow the rules for identifiers defined in Section
    4.4.1.  The use of named parameters applies to the Java Persistence query language, and  is not defined for native queries. <strong>Only
    positional parameter binding may be  portably used for native
    queries.</strong></p>
  </blockquote>