title: Create a Table/Query with JPA/Hibernate in Play Framework
body: <p>So I have Play Framework running at the moment with <strong>JPA</strong> and <strong>Hibernate</strong>. I'm completely new to both and the tutorials I've found around the web are above my head.</p>
  
  <p><strong>How in the world can I send a simple query or create a table?</strong> This is example code I've written up and I get: <code>"RuntimeException: No EntityManager bound to this thread. Try wrapping this call in JPA.withTransaction, or ensure that the HTTP context is setup on this thread."</code></p>
  
  <pre><code>    package controllers;
  
  
  import play.Logger;
  import javax.persistence.Entity;
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.EntityTransaction;
  import javax.persistence.Persistence;
  import javax.persistence.Query;
  
  import play.db.jpa.JPA;
  import play.mvc.Controller;
  import play.db.*;
  
  public class Database {
  
      public static void initbuild() {
          Logger.info("Checking database structure. The database will be restructured if not in the correct format.");
          JPA.em().createQuery("create table test");
  
      }
  }
  </code></pre>