title: Hibernate: Can't use a named parameter for OFFSET and LIMIT?
body: <p>I'm trying to get the following <code>NamedQuery</code> to work:</p>
  
  <pre><code>@NamedQuery(name="MyEntity.findByUser", query="SELECT m FROM MyEntity m WHERE m.owner = :user OFFSET :offset LIMIT :limit")
  </code></pre>
  
  <p>The problem is that this causes Hibernate to explode with the following stack-trace upon server startup:</p>
  
  <pre><code>[INFO] [talledLocalContainer] java.lang.NullPointerException
  [INFO] [talledLocalContainer]   at org.hibernate.hql.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:63)
  [INFO] [talledLocalContainer]   at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:296)
  [INFO] [talledLocalContainer]   at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:97)
  [INFO] [talledLocalContainer]   at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:56)
  [INFO] [talledLocalContainer]   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
  [INFO] [talledLocalContainer]   at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:400)
  [INFO] [talledLocalContainer]   at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:351)
  [INFO] [talledLocalContainer]   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
  [INFO] [talledLocalContainer]   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
  [INFO] [talledLocalContainer]   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
  [INFO] [talledLocalContainer]   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
  [INFO] [talledLocalContainer]   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
  (...)
  </code></pre>
  
  <p>After some trial-and-error I found that replacing ":offset" and ":limit" with literal values (0 and 10, respectively) worked fine.  Is there a reason for this, and is there a way to get the named parameters to work in my query?</p>
  
  <p>I've seen some other examples that use positioned parameters to dynamically set the offset and limit values in a named query, but I'd rather not have my code degenerate into a bunch of unreadable <code>query.setParameter(1, "someValue");</code> nonsense.  Named parameters were supposed to get rid of that kind of garbage code.</p>