2

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 :)

1
  • 1
    did u find any solution of this issue ? Commented Sep 15, 2013 at 13:43

2 Answers 2

1

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

<class>models.Stream</class>
Sign up to request clarification or add additional context in comments.

1 Comment

The error stopped, but now this is being shown: [PersistenceException: [PersistenceUnit: defaultPersistenceUnit] class or package not found] (my persistence.xml is under conf/META-INF)
1

Also make sure which @Entity you have imported,

I had the hibernate class imported, been looking for half an hour or so. Importing javax.persistence.Entity worked...

Not that skilled in Java, but it could be the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.