title: JPA Entity not registered with EntityManager
body: <p>I've been implementing a modular architecture application using Guice, with each application module separated into individual eclipse projects and having it's own Guice module. I've been getting problems with registering JPA entities that are not on the JPA persistence project. The ones inside the project are registered without a problem, but the ones on the other projects are not. There was no problem while the application was implemented on a single project and single Guice module.</p>
  
  <p>The configurations appear to be ok, but most likely there's something I'm missing.
  This is error I get when trying to get an entity from the database:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Not an entity: class org.gradle.security.persistence.jpa.entities.impl.SubjectImpl
  at org.hibernate.jpa.internal.metamodel.MetamodelImpl.entity(MetamodelImpl.java:203)
  at org.hibernate.jpa.criteria.QueryStructure.from(QueryStructure.java:139)
  at org.hibernate.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:173)
  at org.gradle.security.pbeingersistence.jpa.dao.impl.SubjectDAOImpl.findByPrincipal(SubjectDAOImpl.java:48)
  </code></pre>
  
  <p>with the SubjectDAOImpl below and the error when trying to get the entity on the last line,</p>
  
  <pre><code>    public Subject findByPrincipal(String principal, LockModeType lockMode) {
      CriteriaQuery&lt;SubjectImpl&gt; criteria = criteriaQuery(SubjectImpl.class);
      CriteriaBuilder cb = getEM().getCriteriaBuilder();
  
      Root&lt;SubjectImpl&gt; activation = criteria.from(SubjectImpl.class);
      ....
  </code></pre>
  
  <p>with SubjectImpl being:</p>
  
  <pre><code>@Entity
  @Audited
  @Table(name=SubjectImpl.TABLE_NAME, schema=Config.Schemas.DEFAULT)
  public class SubjectImpl extends BaseEntityImpl implements Subject {
  
      public static final String TABLE_NAME = Config.TABLE_PREFIX + "subject";
  
      @Basic(optional = false)
      @Column(name = "principal", unique = true)
      protected String principal;
      ......
  }
  </code></pre>
  
  <p>The Guice modules are configured as follows:</p>
  
  <p>Security Module:</p>
  
  <pre><code>private static class SecurityModule extends AbstractModule {
  
      @Override
      protected void configure() {
          bind(Subject.class).to(SubjectImpl.class).asEagerSingleton();
          ...
          bind(SubjectDAO.class).to(SubjectDAOImpl.class).asEagerSingleton();
      }
  
  }
  </code></pre>
  
  <p>Persistence Module:</p>
  
  <pre><code>public class JPAPersistenceModule extends AbstractModule implements ArchetypeModule {
      @Override
      protected void configure() {
          try {
          Properties props = new Properties();
          InputStream is = new FileInputStream(
                  this.getClass().getClassLoader().getResource(PersistenceProperties.DEFAULT_PROPERTIES_FILE).getPath());
          props.load(is);
          Names.bindProperties(binder(), props);
  
          bind(PersistenceProperties.class).asEagerSingleton();
          JpaPersistModule persistModule = new JpaPersistModule(PersistenceProperties.PERSISTENCE_UNIT);
          persistModule.properties(props);
          install(persistModule);
      } catch (IOException e) {
          LOGGER.error("Could not load persistence module: ", e);
          System.exit(-1);
      }
  }
  </code></pre>
  
  <p>And the server module:</p>
  
  <pre><code>public class ServerModule extends JerseyServletModule implements ArchetypeModule {
      @Override
      protected void configureServlets() {
          filter("/*").through(PersistFilter.class);
          serve("/rest","/rest/*").with(GuiceContainer.class);
      }
  }
  </code></pre>
  
  <p>The Guice modules are installed by this order: JPAPersistenceModule, SecurityModule, ServerModule.
  Can't get my head around the problem, can you give me a hand?</p>