1 Reply Latest reply on Aug 16, 2012 6:27 AM by mperdikeas

    EJB3 code in EAR can't see JPA entities defined in EJB client jar (in /lib) (throws “java.lang.IllegalArgumentException: Not an entity:”)

    mperdikeas Newbie

      I have factored my EJB3 code into:

       

      1. business logic interfaces and JPA @Entity-annotated entity beans (POJOs) that are used to build the "EJB client jar" and
      2. business logic code which implements the business interfaces and does the JPA with the database.

       

      The deployed platform is JBoss AS7.1 with Hibernate JPA.

       

      The idea being that the EJB client jar is the interface which will also be deployed with the war or wars which access the business logic code. I am deploying the EJB3 business logic code as an EAR with no WAR inside (the WAR is deployed independently). Thus, the structure of the top-level business logic EAR is as follows:

       

      ├── lib

      │   ├── commons-lang3-3.1.jar

      │   └── Users-client.jar

      ├── META-INF

      │   ├── application.xml

      │   └── MANIFEST.MF

      └── Users-ejb.jar

      In my case above, the Users-client.jar is the EJB client jar (the interface) and the Users-ejb.jar is business logic implementation and JPA code.

      The structure of the business logic implementation code (Users-ejb.jar) is:

       

      ├── base

      │  └── AbstractFacade.class
      ├── facades

      │   ├── PrivateUserDataFacade.class

      │   └── UserFacade.class ├── META-INF
      │  
      ├── MANIFEST.MF

      │   ├── persistence.xml

      │   └── postgres-ds.xml

      └── utils

          └── JPUtil.class

       

      Where the persistence.xml contains the following tag:

       <exclude-unlisted-classes>false</exclude-unlisted-classes> 

       

      However, with the above setup, code in the Users-ejb.jar does not recognize the @Entity beans defined the Users-client.jar as entities. This is not a class

      not found issue as the code compiles and deploys, rather a 'Not an entity' exception is thrown at runtime.

       

      So, for instance the following test method in class UserFacade.class:

       

      public String boo(String name) {

          javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();

          cq.select(cq.from(User.class)); // <-- exception thrown List<User>

          all = getEntityManager().createQuery(cq).getResultList();

          return "boo"+name;

      }

       

      fails where marked with the trace:

       

      (...)

      Caused by: java.lang.IllegalArgumentException: Not an entity: class entities.User at org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:158) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.criteria.QueryStructure.from(QueryStructure.java:136) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:177) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at facades.UserFacade.boo(UserFacade.java:46) [Users-ejb.jar:]

      (...)

       

      What should I do to ensure that classes found in the lib/Users-client.jar are recognized as Entities by my business logic code?