title: How to pass parameter on jpa query?
body: <p>I have two entities Like <strong>SmsOut</strong> and <strong>SmsIn</strong>. The relation between two entities contains <strong>OneToMany</strong> where <strong>smsIn.id</strong> is <strong>primary key</strong> and <strong>smsOut.sms_in_id</strong> is <strong>foreign key</strong>.</p>
  
  <p>Now I want to pass parameter like <strong>smsIn.mobileNumber</strong>, <strong>smsIn.smsText</strong> and so on, on the query </p>
  
  <pre><code>SELECT so FROM SmsOut so order by id desc
  </code></pre>
  
  <p><strong>Following is my database diagram:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/fMcK2.png" alt="enter image description here"></p>
  
  <p><strong>Edited</strong></p>
  
  <p>Following is my code :</p>
  
  <pre><code>String sql = "SELECT so FROM SmsOut so WHERE so.smsInId.mobileNumber =:mobileNumber AND so.smsInId.smsText =:smsText AND so.smsInId.shortCode =:shortCode between so.smsOutDate =:startDate and so.smsOutDate =:endDate order by id desc";
      Query query = em.createQuery(sql);
      query.setParameter("mobileNumber", mobileNumber);
      query.setParameter("smsText", smsText);
      query.setParameter("shortCode", shortCode);
      query.setParameter("smsOutDate", startDate);
      query.setParameter("smsOutDate", endDate);
      smsOutList = query.getResultList();
  </code></pre>
  
  <p>and exception is :</p>
  
  <pre><code>SEVERE: line 1:188: expecting "and", found '='
  java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: expecting "and", found '=' near line 1, column 188 [SELECT so FROM     com.f1soft.SMSC.entities.SmsOut so WHERE so.smsInId.mobileNumber =:mobileNumber AND so.smsInId.smsText =:smsText AND so.smsInId.shortCode =:shortCode between so.smsOutDate =:startDate and so.smsOutDate =:endDate order by id desc]
  at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:624)
  at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
  </code></pre>
  
  <p>Please Help me.
  Thanks </p>