title: How to work with Jpa in play framework?
body: <p>I am working with Play framework with JPA to store database but some issue is coming :</p>
  
  <p>what am i doing is  i am storing user into database but exception is coming.</p>
  
  <p>My <strong>controller</strong> is:</p>
  
  <pre><code>public class Application extends Controller {
  
  
  
      @Transactional(readOnly=true)
      public static Result index() {
  
          Form&lt;Userd&gt; ud=form(Userd.class);
          return ok(index.render(ud));
      }
      @Transactional
      public static Result enter(){
          Form&lt;Userd&gt; crForm = form(Userd.class).bindFromRequest();
  
          if(crForm.hasErrors()){
  
              return badRequest(index.render(crForm));
          }
          else{
  
              crForm.get().save();
              return ok("value saved");
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>Model</strong> is:</p>
  
  <pre><code>@Entity
  public class Userd {
  
  
      @Required
      public String name;
  
      @Email
      public String email;
      @Id
      public Long empid;
      @Required
      public String password;
  
      public static Userd findById(Long id) {
          return JPA.em().find(Userd.class,id );
      }
      public Userd() {
  
      }
      public Userd(String name, String email, Long empid, String password) {
  
          this.name = name;
          this.email = email;
          this.empid = empid;
          this.password = password;
      }
      public void save(){
          JPA.em().persist(this);
  
      }
  </code></pre>
  
  <p>and <strong>Exception</strong> is:</p>
  
  <pre><code>[RollbackException: Error while committing the transaction] 
  </code></pre>
  
  <p><strong>terminal screen</strong> is :</p>
  
  <pre><code>[info] play - datasource [jdbc:h2:mem:play] bound to JNDI as DefaultDS
  [info] play - database [default] connected at jdbc:h2:mem:play
  [info] play - Application started (Dev)
  [error] o.h.u.JDBCExceptionReporter - Table "USERD" not found; SQL statement:
  insert into Userd (email, name, password, empid) values (?, ?, ?, ?) [42102-168]
  [error] application - 
  
  ! @6fiph0k4b - Internal server error, for (POST) [/login] -&gt;
  
  play.api.Application$$anon$1: Execution exception[[RollbackException: Error while committing the transaction]]
      at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.2]
      at play.api.DefaultApplication.handleError(Application.scala:383) ~[play_2.10.jar:2.1.2]
      at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:143) ~[play_2.10.jar:2.1.2]
      at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:139) ~[play_2.10.jar:2.1.2]
      at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) ~[play_2.10.jar:2.1.2]
      at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) ~[play_2.10.jar:2.1.2]
  javax.persistence.RollbackException: Error while committing the transaction
      at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
      at play.db.jpa.JPA.withTransaction(JPA.java:107) ~[play-java-jpa_2.10.jar:2.1.2]
      at play.db.jpa.TransactionalAction.call(TransactionalAction.java:14) ~[play-java-jpa_2.10.jar:2.1.2]
      at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:80) ~[play_2.10.jar:2.1.2]
      at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:79) ~[play_2.10.jar:2.1.2]
      at play.libs.F$Promise$PromiseActor.onReceive(F.java:425) ~[play_2.10.jar:2.1.2]
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [models.Userd]
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:81) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
      at play.db.jpa.JPA.withTransaction(JPA.java:107) ~[play-java-jpa_2.10.jar:2.1.2]
      at play.db.jpa.TransactionalAction.call(TransactionalAction.java:14) ~[play-java-jpa_2.10.jar:2.1.2]
      at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:80) ~[play_2.10.jar:2.1.2]
  Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [models.Userd]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2454) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
  Caused by: org.h2.jdbc.JdbcSQLException: Table "USERD" not found; SQL statement:
  insert into Userd (email, name, password, empid) values (?, ?, ?, ?) [42102-168]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2.jar:1.3.168]
      at org.h2.message.DbException.get(DbException.java:169) ~[h2.jar:1.3.168]
      at org.h2.message.DbException.get(DbException.java:146) ~[h2.jar:1.3.168]
      at org.h2.command.Parser.readTableOrView(Parser.java:4770) ~[h2.jar:1.3.168]
      at org.h2.command.Parser.readTableOrView(Parser.java:4748) ~[h2.jar:1.3.168]
      at org.h2.command.Parser.parseInsert(Parser.java:958) ~[h2.jar:1.3.168]
  </code></pre>
  
  <p>can any one please give me idea to fix this issue and <strong>is it necessary to create sql file before run the app</strong> </p>
  
  <p>give some idea!</p>
  
  <p><strong>persistence.xml</strong></p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
  
      &lt;persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;non-jta-data-source&gt;DefaultDS&lt;/non-jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>application.conf</strong>:
  u can see on this link:</p>
  
  <p><a href="http://shorttext.com/Zw96Q" rel="nofollow">application.conf</a></p>
  
  <p>it is creating database but it is not creating evolution file in project.</p>