This discussion is archived
12 Replies Latest reply: Jul 11, 2012 3:44 AM by 859967 RSS

EJB Entity not found?

859967 Newbie
Currently Being Moderated
Hi,

It is weird that i am having this error event all my entities even i have listed all the entities in persistent config; i tested with the global option "include all Entity Classes.." too.
I am using glassfish 3.1.2 ; Netbeans 7.1 on XP.

have you got a clue for this?

>
Caused by: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [test.ClassA] in the Metamodel - please verify that the [Entity] class >was referenced in persistence.xml using a specific <class>test.ClassA</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> >element.
thanks,

-Hoang Long

Edited by: CardM on Jun 28, 2012 8:38 PM
  • 1. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    or if you know how to ensure entities are created?

    regards,

    -HL
  • 2. Re: EJB Entity not found?
    r035198x Pro
    Currently Being Moderated
    If you have annotated your Entity classes correctly then you don't need to add entities to an xml file.
    Look at the first line in the stack trace that references your code to see what code gave you that exception and post the line here.
  • 3. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    r035198x wrote:
    If you have annotated your Entity classes correctly then you don't need to add entities to an xml file.
    Look at the first line in the stack trace that references your code to see what code gave you that exception and post the line here.
    stack trace points to a function below:
         protected int countLike(String fieldName, String value) {
             CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
             javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
             javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
            
            
            cq.select(getEntityManager().getCriteriaBuilder().count(rt));
            
            Expression ex = rt.get(fieldName);
            cq.where(cb.like(ex,"%"+ value+"%"));
            
            javax.persistence.Query q = getEntityManager().createQuery(cq);        
            return ((Long) q.getSingleResult()).intValue();
        }  
    the line it points to:
    javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
    and i assure the entity is annotated @Entity (it is auto generated from netbeans)

    regards,

    -HL

    Edited by: CardM on Jun 29, 2012 3:23 AM
  • 4. Re: EJB Entity not found?
    r035198x Pro
    Currently Being Moderated
    Did you printout the value of entityClass to confirm that it's the right class being referenced?
  • 5. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    r035198x wrote:
    Did you printout the value of entityClass to confirm that it's the right class being referenced?
    yes, it is the right class. And i forgot this input: it failed some time; sometimes it works. So i am thinking the reason from Glassfish itself. How i made it work: undeploy and redeploy several times there will be a chance it works. This is annoying though.
  • 6. Re: EJB Entity not found?
    r035198x Pro
    Currently Being Moderated
    CardM wrote:
    r035198x wrote:
    Did you printout the value of entityClass to confirm that it's the right class being referenced?
    yes, it is the right class. And i forgot this input: it failed some time; sometimes it works. So i am thinking the reason from Glassfish itself. How i made it work: undeploy and redeploy several times there will be a chance it works. This is annoying though.
    You have classpath issues here. Devote some time to understanding how you are building your deployment file.
  • 7. Re: EJB Entity not found?
    gimbal2 Guru
    Currently Being Moderated
    r035198x wrote:
    CardM wrote:
    r035198x wrote:
    Did you printout the value of entityClass to confirm that it's the right class being referenced?
    yes, it is the right class. And i forgot this input: it failed some time; sometimes it works. So i am thinking the reason from Glassfish itself. How i made it work: undeploy and redeploy several times there will be a chance it works. This is annoying though.
    You have classpath issues here. Devote some time to understanding how you are building your deployment file.
    Not surprising, seeing how the other thread has exactly the same theme.

    Class cast exception EJB 3.0
  • 8. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    Hi,

    I used web admin console provided by Glassfish 3.1.2 to deploy the application. And it happens more frequently on my server than deploying in local machine (in local machine i can "clean and build" then "deploy" using netbeans functions or also from Glassfish web admin console and i gain more chance of success (can browse web without entity not found issue)).

    I am still getting stuck in resolving this issue. Could you point out more details how i can make my class path more properly?

    regards,

    -Hoang Long
  • 9. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    I tried to package all entities to single jar file; and added it to "lib" folder under "WEB-INF". By doing this, i can ensure class path is referenced to all entities. But the issue still appeared.

    I am still investigating if there is a work around.

    A clear response is really appreciated.

    regards,

    -Hoang Long
  • 10. Re: EJB Entity not found?
    r035198x Pro
    Currently Being Moderated
    Are you deploying a war file or ear file?
    Also make sure that there are no older versions of those classes already deployed into your container.
  • 11. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    r035198x wrote:
    Are you deploying a war file or ear file?
    Also make sure that there are no older versions of those classes already deployed into your container.
    I am deploying war file. And before deployment, i always use "undeploy" function provided by Web admin console to undeploy earlier version.

    i have tried with "Force Redeploy" either.

    Edited by: CardM on Jul 10, 2012 6:00 PM
  • 12. Re: EJB Entity not found?
    859967 Newbie
    Currently Being Moderated
    another thing that i investigated: I saw the MetaModel file appeared together with the entity class in my "class" folder on glassfish applications. So it is sure to be there.

    And if i decompiled entity class, i saw the @Entity there; if i decompiled metamodel class, i saw it points to correct entity class.

    A weird situation too: I used this code to check entities and i found the "missing" one still appeared in server log.
      Metamodel m = getEntityManager().getMetamodel();
           for(EntityType t : m.getEntities() ){
               System.out.println("*** Entity: " + t.getName() + ":OK");
           }
    Edited by: CardM on Jul 11, 2012 3:43 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points