IllegalArgumentException: Unknown Entity: Models Using JPA in Play Framework 2

advertisements

I'm trying to persist data with Play 2 using JPA, but i'm getting: Execution exception [IllegalArgumentException: Unknown entity: models.Stream];

Stream.java `

package models;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import javax.persistence.Persistence;

import com.restfb.Facebook;

@Entity
public class Stream {
  @Facebook
  @Id
  public String post_id;

  @Facebook
  public String created_time;

  @Facebook
  public String message;

  @Facebook
  public String permalink;

  @Override
  public String toString() {
    return String.format("%s, %s, %s, %s", created_time, message, permalink, post_id);
  }

  public void save(){
      EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit");
      EntityManager entityManager = entityManagerFactory.createEntityManager();
      entityManager.getTransaction().begin();
      entityManager.persist(this);
      entityManager.getTransaction().commit();
      entityManager.close();
  }
}

`

persistence.xml

`

<persistence-unit name="defaultPersistenceUnit">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/fiatbr_db"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value="1234"/>
        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hbm2ddl.auto" value="create"/>
    </properties>
</persistence-unit>

`

There is something missing? Any configuration misconfigured? It looks like the model Stream is not found, but how it cannot be? There is something more to add further the annotation @Entity in the class? Thanks :)


The entity class is not listed in your persistence.xml file:

<class>models.Stream</class>