7 Replies Latest reply on Apr 14, 2014 3:44 PM by Michael Jank

    errai JPA: entity types empty

    Michael Jank Newbie

      Hi,

       

      I am trying to get errai JPA running, but am stuck with a strange problem: the entity types held be the ErraiMetamodel are empty, as if my entity could be found by the errai scanner - if I understood correctly that all classes annotated with "@Entity" are detected as entity.

      So as soon as I try to find or persist an entity, I get an gwt UmbrellaException: my entity "is not a known entity type" and the entityTypes map is emtpy.


      I am using errai 2.4.0.Final and Tomcat 7.0.42.


      My test entity looks like:

      @NamedQuery(name="searchLocation", query="SELECT l FROM LocationListItem l WHERE l.locationPath LIKE :search")

      @Entity @Portable

      public class Item {

          @GeneratedValue @Id private Long id;

          private String name;

       

          public Item() {  }

       

          public Item(String name) {

              this.name= name;

          }

      ...

      }

       

      My test code is like:

      @Inject private EntityManager em;

      ...

      em.persist(new Response("test"));

       

      My gwt.xml contains the entries:

         <inherits name="org.jboss.errai.common.ErraiCommon"/>

          <inherits name="org.jboss.errai.bus.ErraiBus"/>

          <inherits name="org.jboss.errai.enterprise.CDI"/>

          <inherits name="org.jboss.errai.jpa.JPA"/>

          <inherits name="org.jboss.errai.databinding.DataBinding" />

          <inherits name="org.jboss.errai.ui.UI" />

          <inherits name="org.jboss.errai.ui.nav.Navigation"/>

          <inherits name="org.jboss.errai.enterprise.Jaxrs"/>

          <inherits name="org.jboss.errai.validation.Validation" />

          <inherits name="org.hibernate.validator.HibernateValidator" />

          <inherits name="org.jboss.errai.ioc.Container"/>

       

      And hints what I did wrong or missed to configure?

       

      Thank you,

      Michael

        • 1. Re: errai JPA: entity types empty
          Jonathan Fuerth Master

          Hi Michael,

           

          It looks like you've done everything correctly, so I'm at a bit of a loss. Some things you can check:

           

          1. Try the Errai JPA demo apps: errai/errai-demos/errai-jpa-demo-basic at master · errai/errai · GitHub and errai/errai-demos/errai-jpa-demo-todo-list at master · errai/errai · GitHub and ensure they work in your environment. If so, compare your app's setup to these demos.

          2. Are you certain that ErraiEntityManagerGenerator is running at rebind time? I can't see why not, since you are inheriting its GWT module, but worth checking in the Dev Mode console log...

          3. Enable DEBUG logging for org.jboss.errai.jpa at rebind time, and ensure it's seeing your entities during its scan (see log4j.properties and pom.xml in one of the JPA demo apps for clues on the configuration).

          4. Run Dev Mode in debug (mvn gwt:debug), attach your IDE, and set a breakpoint in ErraiEntityManagerGenerator.createHibernateEntityManagerFactory(), paying special attention to how it builds the "managedTypeNames" list. Every type added to this list should be available in the client-side ErraiMetamodel.

           

          Hope that helps!

          1 of 1 people found this helpful
          • 2. Re: errai JPA: entity types empty
            Jonathan Fuerth Master

            Something else to try before the other stuff: it's possible that your entity classes have some non-translatable code in them, and this is making them invisible in the GWT TypeOracle. To check this, set up your GWT build for strict mode (-strict as a command line parameter, or <strict>true</strict> in gwt-maven-plugin configuration) and run a full production-mode build. (note that strict mode has no effect on Dev Mode; you have to do a full compile).

             

            -Jonathan

            • 3. Re: errai JPA: entity types empty
              Michel Werren Novice

              Hello

               

              Another hint can be maybe the validation messages during the compilation. You have to ensure, thats the JPA annotations are reachable by the GWT compiler (when the entities are in a separate Maven module for instance). When they are not reachable, this classes are may removed silently. As Jonathan already mentioned, try to see the problem with DEBUG.

               

              Regards

              Michel

              • 4. Re: errai JPA: entity types empty
                Michael Jank Newbie

                Hi Jonathan and Michel,

                 

                thank you for your quick responses!

                 

                What I should mention is that I work with gradle. I debugged a bit the scanning of the classes and the ErraiEntityManagerGenerator, what I found is that my entity class is not scanned by MetadataScanner but ErraiEntityManagerGenerator.createHibernateEntityManagerFactory is called.

                When building the project with maven and start mvn:debug, the scanning by MetadataScanner happens before creating the EntityManagerFactory, so things work fine. Therefore I think I missed something when configuring and starting the gwt compiler/devMode with gradle. But I am still working on this.

                 

                Cheers,

                Michael

                • 5. Re: errai JPA: entity types empty
                  Michael Jank Newbie

                  Also tried a bit playing with the system variable errai.reflections.cache, when starting in dev mode, setting it to true helps, and the test entity is written into the cache file. But in a normal assemble (no devmode) the test entity is missing in the cache file.

                  • 6. Re: errai JPA: entity types empty
                    Michel Werren Novice

                    Sorry, i am not really familiar with gradle. Can you attach your project?

                    • 7. Re: errai JPA: entity types empty
                      Michael Jank Newbie

                      The problem was that when copying together the files during the build, some resource files were missing in this stage of the build, especially the ErraiApp.properties. As soon as the resource files were included correctly soon enough, the MetadataScanner of course found the entities.

                       

                      We are now also using the gwt gradle plugin, so that's now one obvious error less to make...

                       

                      Thanks for all your help, Jonathan and Michel!