title: Table name as parameter in HQL
body: <p>Let's assume we have the HQL query:</p>
  
  <pre><code>String ageQuery = "select age from people where name = :name";
  
  Session session = getSession();
  Query query = session.
          createSQLQuery(nameQuery).
          setParameter("name", "Thomas");
  // query.list(); returns the result
  </code></pre>
  
  <p>But what if I want to parametrize the table name? One can't use it like this:</p>
  
  <pre><code>String ageQuery = "select :table from people where name = :name";
  
  Session session = getSession();
  Query query = session.
          createSQLQuery(ageQuery).
          setParameter("table", "age").
          setParameter("name", "Thomas");
  </code></pre>
  
  <p>I've applied the workaround:</p>
  
  <pre><code>String ageQuery = "select :table: from people where name = :name";
  
  Session session = getSession();
  Query query = session.
          createSQLQuery(ageQuery.
          replace(":table:", "age")).
          setParameter("name", "Thomas");
  </code></pre>
  
  <p>... but I don't really like it. Is there any other solution?</p>